on 10-23-2015 4:07 PM
Hello,
I would like to create dynamic SQL using a WHERE statement.
The user would enter P_Location as an input parameter and then I would like to do something like:
WHERE "Location" = :P_Location
Thank you,
Fred
Actually just figured out how to do it:
WHERE "Location" >= :P_Location
But the only issue is that is does not actually substitute.
For example I get results like, Location="R300"
When I entered P_Location=R110
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yes, the result is totally right. You're telling to return all data, that is larger/equal than/to the string R110 (R300 obviously is).
You might try something like:
DECLARE temp NVARCHAR(255);
IF : P_Location = ''
THEN
:temp = '%';
ELSE
:temp = : P_location
ENDIF.
...WHERE Location LIKE :temp;
Please tell me, if this works for you.
Kind regards,
Daniel
Instead of fiddling with the SQL statement and creating dynamic SQL manually, you might want to check the SAP HANA documentation and use the APPLY_FILTER (APPLY_FILTER - SAP HANA SQLScript Reference - SAP Library) function.
This removes your boilerplate code and makes it pretty explicit, what you are doing there.
User | Count |
---|---|
87 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.