0

I am trying to "translate" the following command into dynamic SQL to be used in a procedure:

SELECT *, 'IDS' AS SYSID FROM MODE_TEST.USR02

Can someone help with this question? I am facing problems with the 'IDS'.

thanks,

regards,

nwellnhof
  • 32,319
  • 7
  • 89
  • 113
  • 1
    Please, clarify, what is dynamic in this code and what the *problems* do you have? If this is some errors, then please post them here as plain text. – astentx Jun 22 '21 at 16:11

1 Answers1

0

You can use like below:

do begin
declare str nvarchar(1000);
str='SELECT *,''IDS'' AS "SIYSID" FROM MODE_TEST.USR02';
execute immediate :str;
end;
Suchitra
  • 101
  • 1
  • 3
  • 1
    It has no difference compared to plain select. So what is the reason to complicate simple and straightforward way to do simple tasks? – astentx Jun 24 '21 at 11:26
  • The question was to embed the select stmt as dynamic SQL within procedure, and pass a value ( which is IDS) in a column within single quotes, hence the answer. – Suchitra Jun 25 '21 at 15:27
  • Dynamic call just to make it dynamic makes no sense. This way instead of plain `select` statement you may also join to `dummy` table or do any other identity transformation, but what is the purpose? – astentx Jun 25 '21 at 17:52
  • In HANA DB, in order to capture results from select , we need to execute it using 'execute immediately' clause, questioner must have had the requirement. – Suchitra Jun 26 '21 at 06:31