问题
can I place a sql query in a sql hana place holder?
the following query works:
Select * From table1
('PLACEHOLDER' = ('$$IP_ShipmentDate$$', '2020-01-01'))
I am trying to pass something like the following:
Select * From table1
('PLACEHOLDER' = ('$$IP_ShipmentDate$$',
Select TO_VARCHAR(min("some_date"),'YYYY-MM-DD') from Table2)
Currently getting a syntex error
回答1:
As error says you, expressions are not supported for column view parameter: Can't use column expression as column view parameter
.
However, there are options to calculate it:
- If your parameter's value is semantically related to this calculated view (e.g. you need some default value for this view that is calculated based on some logic), then you can create a stored procedure with one output parameter to calculate the value, and use parameter type Derived From Procedure/Scalar Function. To make that value adjustable from frontend you can mark it as Input enabled. Or if calculated value is based on user input, you can map input parameters of procedure to input parameters of calculation view in section Parameters/Variables -> Procedures/Scalar functions for input parameters.
create procedure sp_dummy (
in dummy nvarchar(10) default '0',
out val nvarchar(10)
)
as begin
val = to_char(current_date, 'yyyymmdd');
end;
- If your parameter's value is not related to calculation view and you just use calculation view to get some data for that value, you can use the result set feature of stored procedure/SQLScript block. If your SQL executor does not attempt to parse SQL statement (for example, SAP BO checks for
SELECT
as the first SQL word after some SP onwards, so this way will not be valid for it) and just gets result set as metadata for column definitions, then you can avoid extra object to wrap calculation logic.
To return a result set, use a SELECT statement because anonymous blocks do not have any parameters defined.
do begin
declare lv_param nvarchar(100);
select max('some_date')
into lv_param
from dummy /*your_table*/;
select *
from "_SYS_BIC"."path.to.your.view/CV_TEST" (
PLACEHOLDER."$$P_DUMMY$$" => :lv_param
);
end;
That with calculation view based on the table RSPCLOGCHAIN
filtered by output of the procedure declared above gives me
LOG_ID | DATUM | INPUT_PARAM | CUR_DATE
--------------------------+----------+-------------+----------
8FRV39X1O8814X6IJMLPI47PV | 20201221 | some_date | 20201221
C7S9EY3J0GYA76Y2S9CIA39QR | 20201221 | some_date | 20201221
35R8A3RFUG00EBY8MZQWJLIXF | 20201221 | some_date | 20201221
850MVHOJIKIDD7EVY6WFIYPZN | 20201221 | some_date | 20201221
回答2:
No, that's not supported.
The parameter interface is for character strings only. SELECTs or expressions won't be evaluated by HANA.
To achieve dynamic selection parameters (say, the current date or three weeks ago) you may want to look into setting the default values via stored procedures or into computing the desired values in the client (front-end) tool.
来源:https://stackoverflow.com/questions/65305725/can-i-place-a-sql-query-in-a-sql-hana-place-holder