<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>Question Re: EXEC command not working as expected in Datasphere SQ... in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/exec-command-not-working-as-expected-in-datasphere-sql-view/qaa-p/13785174#M4840237</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;First, the dynamic sql you prepared has some issues, it will concentrate the value(1) of variable "cur" into the sql statement.&lt;/P&gt;&lt;P&gt;Second, the dynamic sql does not allow an INTO clause.&lt;/P&gt;&lt;P&gt;Here is my new script, hope it can fulfill your requirements:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;DECLARE dyn_sql NVARCHAR(5000);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;DECLARE cur ITABLE("VAL" BIGINT);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;DECLARE curr TABLE("VAL" BIGINT);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;dyn_sql =&amp;nbsp;&lt;SPAN&gt; 'SELECT COUNT(*) as VAL&amp;nbsp; FROM AUFK';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;EXEC dys INTO cur;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;INSERT INTO :curr (VAL) SELECT VAL FROM :cur;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RETURN SELECT * FROM :CURR;&lt;/SPAN&gt;&lt;/P&gt;</description>
    <pubDate>Wed, 07 Aug 2024 03:22:31 GMT</pubDate>
    <dc:creator>Simon_Ye</dc:creator>
    <dc:date>2024-08-07T03:22:31Z</dc:date>
    <item>
      <title>EXEC command not working as expected in Datasphere SQL view</title>
      <link>https://community.sap.com/t5/technology-q-a/exec-command-not-working-as-expected-in-datasphere-sql-view/qaq-p/13782691</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm trying to create a Datasphere SQL view type SQLScript and using the EXEC command as below,&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;DECLARE cur INTEGER:=1;&lt;BR /&gt;DECLARE curr TABLE("VAL" BIGINT);&lt;BR /&gt;EXEC 'SELECT COUNT(*) INTO ' || cur ||' FROM AUFK';&lt;BR /&gt;INSERT INTO :curr values(cur);&lt;BR /&gt;RETURN SELECT * FROM :CURR;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Below is the error :&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;sql syntax error: incorrect syntax near "1": line 1 col 22 (at pos 22)&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;But, when I use the plain select as below, it works.&lt;/P&gt;&lt;P&gt;SELECT COUNT(*) INTO curr FROM AUFK;&lt;/P&gt;&lt;P&gt;We need the exec command as we want to run this code in loop for multiple tables. and make AUFK also as a variable for tablename.&lt;/P&gt;&lt;P&gt;Any help is much appreciated.&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;__PRESENT&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 05 Aug 2024 07:06:29 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/exec-command-not-working-as-expected-in-datasphere-sql-view/qaq-p/13782691</guid>
      <dc:creator>EshwarReddy</dc:creator>
      <dc:date>2024-08-05T07:06:29Z</dc:date>
    </item>
    <item>
      <title>Re: EXEC command not working as expected in Datasphere SQ...</title>
      <link>https://community.sap.com/t5/technology-q-a/exec-command-not-working-as-expected-in-datasphere-sql-view/qaa-p/13785174#M4840237</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;First, the dynamic sql you prepared has some issues, it will concentrate the value(1) of variable "cur" into the sql statement.&lt;/P&gt;&lt;P&gt;Second, the dynamic sql does not allow an INTO clause.&lt;/P&gt;&lt;P&gt;Here is my new script, hope it can fulfill your requirements:&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;DECLARE dyn_sql NVARCHAR(5000);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;DECLARE cur ITABLE("VAL" BIGINT);&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;DECLARE curr TABLE("VAL" BIGINT);&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;dyn_sql =&amp;nbsp;&lt;SPAN&gt; 'SELECT COUNT(*) as VAL&amp;nbsp; FROM AUFK';&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;EXEC dys INTO cur;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;INSERT INTO :curr (VAL) SELECT VAL FROM :cur;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;RETURN SELECT * FROM :CURR;&lt;/SPAN&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 07 Aug 2024 03:22:31 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/exec-command-not-working-as-expected-in-datasphere-sql-view/qaa-p/13785174#M4840237</guid>
      <dc:creator>Simon_Ye</dc:creator>
      <dc:date>2024-08-07T03:22:31Z</dc:date>
    </item>
  </channel>
</rss>

