Skip to Content

SAP HANA Execute Immediate with [INTO ]

Feb 20 at 09:42 AM


avatar image

The Documentation for Execute Immediate unfortunately does not show how to use the into statement.

So how can i store the result of a dynamic SQL in a variable?


I need dynamic SQL since the table name and columns are variables like this:

dynSql := 'SELECT max(' || searchColName || ') ' || char(10);
dynSql := dynSql || 'FROM ' || tbl || char(10);
dynSql := dynSql || 'WHERE ' || whereColName || ' = ''' || whereColValue || '''';

execute immediate dynSql;-- into outputValue;

The variable content could be:

select max(TIMESTAMP)
where "UniqueId" = 'XXX123XX-EA9E-43F4-AB27-104B3E4DXXXX';

So how can i store the value of TIMESTAMP in the output variable of the stored proceedure?

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

1 Answer

Florian Pfeffer
Feb 20 at 10:03 AM

I think the documentation is already quite clear regarding that (also not providing a code example). But you can check the blog here for an example.


PS: I assume you have already a HANA 2.0 SPS01 system to have this feature supported.

Show 2 Share
10 |10000 characters needed characters left characters exceeded

OK that's the reason why it's not working.
We do not have HANA 2.0
Thx for the hint.

How to do it with HANA 1.0
with a temporary table?


Jep, with all the overload coming with it.