<?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: EXECUTE IMMEDIATE with variable references in Technology Q&amp;A</title>
    <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-variable-references/qaa-p/13815097#M4845940</link>
    <description>&lt;P&gt;Yes, and even statements to fill local variables based on a dynamic query can usually be written as one single statement, such as&lt;/P&gt;
&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;/SPAN&gt;Set myVar = (query)
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;or via SELECT INTO. 
I guess Arthoor is fully aware of that.
Personally, I ran into the compound statement limit several times, otherwise Mark would not have had to comment then...&lt;/P&gt;</description>
    <pubDate>Sat, 27 Jul 2019 06:03:09 GMT</pubDate>
    <dc:creator>VolkerBarth</dc:creator>
    <dc:date>2019-07-27T06:03:09Z</dc:date>
    <item>
      <title>EXECUTE IMMEDIATE with variable references</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-variable-references/qaq-p/13815093</link>
      <description>&lt;P&gt;According to EXECUTE IMMEDIATE statement &lt;A href="http://dcx.sap.com/sa160/en/dbreference/execute-immediate-statement.html" target="_blank"&gt;docs&lt;/A&gt;:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;Only global variables can be referenced in a statement executed by EXECUTE IMMEDIATE.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;I have three cases that show this is not always true at least in builds 16.0.0.2614 and 17.0.10.5771 (and 11.0.1.3158).&lt;/P&gt;
&lt;P&gt;Case a) works despite referencing local variable:
&lt;/P&gt;&lt;PRE&gt;BEGIN
    DECLARE &lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;@a&lt;/A&gt; BIT;
    SET &lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;@a&lt;/A&gt; = 0;
    EXECUTE IMMEDIATE 'SET &lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;@a&lt;/A&gt; = IF &lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;@a&lt;/A&gt; = 0 THEN 1 ELSE &lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;@a&lt;/A&gt; ENDIF';
    SELECT &lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/320/arthoor" target="_blank"&gt;@a&lt;/A&gt;;
END
&lt;/PRE&gt;
Case b) should do the same but throws &lt;EM&gt;Column '&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;@b&lt;/A&gt;' not found&lt;/EM&gt; error (however, this behavior meets the docs):
&lt;PRE&gt;BEGIN
    DECLARE &lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;@b&lt;/A&gt; BIT;
    SET &lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;@b&lt;/A&gt; = 0;
    EXECUTE IMMEDIATE 'IF &lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;@b&lt;/A&gt; = 0 THEN SET &lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;@b&lt;/A&gt; = 1 END IF';
    SELECT &lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/401/bytronics1" target="_blank"&gt;@b&lt;/A&gt;;
END
&lt;/PRE&gt;
Case c) works (this behavior meets the docs if we name &lt;EM&gt;connection&lt;/EM&gt; variables as &lt;EM&gt;global&lt;/EM&gt;):
&lt;PRE&gt;BEGIN
    CREATE VARIABLE &lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;@c&lt;/A&gt; BIT;
    SET &lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;@c&lt;/A&gt; = 0;
    EXECUTE IMMEDIATE 'IF &lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;@c&lt;/A&gt; = 0 THEN SET &lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;@c&lt;/A&gt; = 1 END IF';
    SELECT &lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;&lt;/A&gt;&lt;A href="http://sqlanywhere-forum.sap.com/users/127/chipshot" target="_blank"&gt;@c&lt;/A&gt;;
END
&lt;/PRE&gt;
Could someone from SAP explain the reasons of the different behavior in cases a) and b)? Can it be fixed/improved in future releases? I would expect that case b) would work too (and the docs would be modified accordingly), i. e. NO, I'm NOT expecting case a) to stop working just to meet the docs. &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 01:01:49 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-variable-references/qaq-p/13815093</guid>
      <dc:creator>former_SQLA_member1694875</dc:creator>
      <dc:date>2019-07-09T01:01:49Z</dc:date>
    </item>
    <item>
      <title>Re: EXECUTE IMMEDIATE with variable references</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-variable-references/qaa-p/13815094#M4845937</link>
      <description>&lt;P&gt;See &lt;A href="https://sqlanywhere-forum.sap.com/questions/547#2545"&gt;this older comment&lt;/A&gt; from Mark:&lt;/P&gt;
&lt;BLOCKQUOTE&gt;
&lt;P&gt;As long as the EXECUTE IMMEDIATE statement is a single statement then the statement runs in the same context as the calling block - if it is a compound statement, then it runs as a batch an hence runs within its own scope and would not have access to the calling scope's variables.&lt;/P&gt;
&lt;/BLOCKQUOTE&gt;
&lt;P&gt;In my understanding, your case a) uses one single SET statement whereas case b) uses a batch (i.e. several statements).&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 05:43:12 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-variable-references/qaa-p/13815094#M4845937</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2019-07-09T05:43:12Z</dc:date>
    </item>
    <item>
      <title>Re: EXECUTE IMMEDIATE with variable references</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-variable-references/qaa-p/13815096#M4845939</link>
      <description>&lt;P&gt;Understood. Thanks.&lt;/P&gt;</description>
      <pubDate>Tue, 09 Jul 2019 08:28:47 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-variable-references/qaa-p/13815096#M4845939</guid>
      <dc:creator>former_SQLA_member1694875</dc:creator>
      <dc:date>2019-07-09T08:28:47Z</dc:date>
    </item>
    <item>
      <title>Re: EXECUTE IMMEDIATE with variable references</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-variable-references/qaa-p/13815095#M4845938</link>
      <description>&lt;P&gt;Volker's answer is correct... &lt;B&gt;but&lt;/B&gt; it omits Mark's first sentence where he says the &lt;B&gt;"statement about needing to use CREATE VARIABLE is not correct"&lt;/B&gt;...&lt;/P&gt;
&lt;P&gt;...hence this &lt;B&gt;rant...&lt;/B&gt; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;In the real world the vast majority of EXECUTE IMMEDIATE statements are &lt;B&gt;single statements&lt;/B&gt; rather than compound statements. In particular, a huge SELECT, INSERT, DELETE or UPDATE statement is still a single statement no matter how many derived tables, CASE and IF expressions, and JOIN conditions involving procedure calls it contains.&lt;/P&gt;
&lt;P&gt;As such, an EXECUTE IMMEDIATE can contain as many references to local variables you want, and you do NOT have to use CREATE VARIABLE.&lt;/P&gt;
&lt;P&gt;In particular, Foxhound contains dozens (hundreds?) of EXECUTE IMMEDIATEs and not one of them had to resort to CREATE VARIABLE.&lt;/P&gt;
&lt;P&gt;...in fact, I was not even aware of the compound statement restriction &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://media.tenor.com/images/230e3f655f5eb68b48afbcaa83b93192/tenor.gif" /&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jul 2019 09:56:54 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-variable-references/qaa-p/13815095#M4845938</guid>
      <dc:creator>Breck_Carter</dc:creator>
      <dc:date>2019-07-26T09:56:54Z</dc:date>
    </item>
    <item>
      <title>Re: EXECUTE IMMEDIATE with variable references</title>
      <link>https://community.sap.com/t5/technology-q-a/execute-immediate-with-variable-references/qaa-p/13815097#M4845940</link>
      <description>&lt;P&gt;Yes, and even statements to fill local variables based on a dynamic query can usually be written as one single statement, such as&lt;/P&gt;
&lt;DIV&gt;&lt;PRE&gt;&lt;SPAN&gt;&lt;/SPAN&gt;Set myVar = (query)
&lt;/PRE&gt;&lt;/DIV&gt;


&lt;P&gt;or via SELECT INTO. 
I guess Arthoor is fully aware of that.
Personally, I ran into the compound statement limit several times, otherwise Mark would not have had to comment then...&lt;/P&gt;</description>
      <pubDate>Sat, 27 Jul 2019 06:03:09 GMT</pubDate>
      <guid>https://community.sap.com/t5/technology-q-a/execute-immediate-with-variable-references/qaa-p/13815097#M4845940</guid>
      <dc:creator>VolkerBarth</dc:creator>
      <dc:date>2019-07-27T06:03:09Z</dc:date>
    </item>
  </channel>
</rss>

