Skip to Content
0
Feb 20, 2018 at 09:42 AM

SAP HANA Execute Immediate with [INTO ]

4731 Views

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?

Background:

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)
from "SCHEMA"."TABLE"
where "UniqueId" = 'XXX123XX-EA9E-43F4-AB27-104B3E4DXXXX';

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