Quantcast
Channel: SCN : Unanswered Discussions - SAP HANA and In-Memory Computing
Viewing all articles
Browse latest Browse all 4343

How to retrieve values from dynamic SQL

$
0
0

Hi Experts,

 

In my case, I have to use Dynamic SQL to build the query string because the table name is variable.   


Anyone know how to retrieve values ​​from a dynamic SQL running on HANA without use any table or temporaly table.

 

I testing with the CE function, but unfortunately CE functions not supports string with tablename value.

                                       

In Microsoft SQL-SERVER use the following syntax:

SET @SQLString = 'SELECT TOP 1 @DocTypeOUT = DocType  FROM ' + @tbl + ' WHERE DocEntry = ' + @list_of_cols_val_tab_del  SET @ParmDefinition = N'@DocTypeOUT nvarchar(1) OUTPUT';  execute sp_executesql @SQLString, @ParmDefinition,@DocTypeOUT = @DocType  OUTPUT;

In HANA use the following syntax:

CREATE LOCAL TEMPORARY TABLE #TABLE_VALUES(                DocType nvarchar(5) );                SQLString := 'INSERT INTO #TABLE_VALUES (DocType) SELECT TOP 1 "DocType" as "DOCTYPE"  FROM ' || tbl || ' WHERE "DocEntry" = ' || list_of_cols_val_tab_del;                EXEC SQLString;                              SELECT DocType into DocType FROM #TABLE_VALUES;              DROP TABLE #TABLE_VALUES;

Thank you in advance for your help.


Viewing all articles
Browse latest Browse all 4343

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>