<?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>topic create a VIEW with UNION and WHILE in Application Development and Automation Discussions</title>
    <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-view-with-union-and-while/m-p/12385325#M1994388</link>
    <description>&lt;P&gt;I'm creating a VIEW (to be used as Excel pivot source) that collects data from five different tables. I coded it in MS SQL Server Management Studio and it works fine, but when I copy it to the VIEW I get the error (Unable to parse).&lt;/P&gt;
  &lt;P&gt;The SQL is like this:&lt;/P&gt;
  &lt;P&gt;SELECT *&lt;BR /&gt;INTO #tmp&lt;BR /&gt;FROM (&lt;BR /&gt; SELECT a,b,c&lt;BR /&gt; FROM tableONE&lt;BR /&gt; UNION ALL&lt;BR /&gt; SELECT a,b,c&lt;BR /&gt; FROM tableTWO&lt;BR /&gt; UNION ALL&lt;BR /&gt; SELECT a,b,c&lt;BR /&gt; FROM tableTHREE&lt;BR /&gt; UNION ALL&lt;BR /&gt; SELECT a,b,c&lt;BR /&gt; FROM tableFOUR&lt;BR /&gt; ) tmp&lt;BR /&gt;DECLARE @cnt INT = 1&lt;BR /&gt;WHILE @cnt &amp;lt; 13&lt;BR /&gt;BEGIN&lt;BR /&gt;insert into #tmp &lt;BR /&gt;select a,b,@cnt as c&lt;BR /&gt;from tableFIVE&lt;BR /&gt;SET @cnt = @cnt + 1&lt;BR /&gt;END&lt;BR /&gt;select * from #tmp&lt;BR /&gt;DROP TABLE #tmp&lt;/P&gt;
  &lt;P&gt;As I wrote above, it WORKS, but not as a VIEW&lt;/P&gt;
  &lt;P&gt;The only "solution" I can imagine is to remove the #tmp table and make an UNION of all 16 (4+12) select statements&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt;Any tip about this?&lt;/P&gt;
  &lt;P&gt;TIA,&lt;/P&gt;
  &lt;P&gt;Giovanni&lt;/P&gt;</description>
    <pubDate>Wed, 31 Mar 2021 09:16:39 GMT</pubDate>
    <dc:creator>former_member651578</dc:creator>
    <dc:date>2021-03-31T09:16:39Z</dc:date>
    <item>
      <title>create a VIEW with UNION and WHILE</title>
      <link>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-view-with-union-and-while/m-p/12385325#M1994388</link>
      <description>&lt;P&gt;I'm creating a VIEW (to be used as Excel pivot source) that collects data from five different tables. I coded it in MS SQL Server Management Studio and it works fine, but when I copy it to the VIEW I get the error (Unable to parse).&lt;/P&gt;
  &lt;P&gt;The SQL is like this:&lt;/P&gt;
  &lt;P&gt;SELECT *&lt;BR /&gt;INTO #tmp&lt;BR /&gt;FROM (&lt;BR /&gt; SELECT a,b,c&lt;BR /&gt; FROM tableONE&lt;BR /&gt; UNION ALL&lt;BR /&gt; SELECT a,b,c&lt;BR /&gt; FROM tableTWO&lt;BR /&gt; UNION ALL&lt;BR /&gt; SELECT a,b,c&lt;BR /&gt; FROM tableTHREE&lt;BR /&gt; UNION ALL&lt;BR /&gt; SELECT a,b,c&lt;BR /&gt; FROM tableFOUR&lt;BR /&gt; ) tmp&lt;BR /&gt;DECLARE @cnt INT = 1&lt;BR /&gt;WHILE @cnt &amp;lt; 13&lt;BR /&gt;BEGIN&lt;BR /&gt;insert into #tmp &lt;BR /&gt;select a,b,@cnt as c&lt;BR /&gt;from tableFIVE&lt;BR /&gt;SET @cnt = @cnt + 1&lt;BR /&gt;END&lt;BR /&gt;select * from #tmp&lt;BR /&gt;DROP TABLE #tmp&lt;/P&gt;
  &lt;P&gt;As I wrote above, it WORKS, but not as a VIEW&lt;/P&gt;
  &lt;P&gt;The only "solution" I can imagine is to remove the #tmp table and make an UNION of all 16 (4+12) select statements&lt;/P&gt;
  &lt;P&gt;&lt;BR /&gt;Any tip about this?&lt;/P&gt;
  &lt;P&gt;TIA,&lt;/P&gt;
  &lt;P&gt;Giovanni&lt;/P&gt;</description>
      <pubDate>Wed, 31 Mar 2021 09:16:39 GMT</pubDate>
      <guid>https://community.sap.com/t5/application-development-and-automation-discussions/create-a-view-with-union-and-while/m-p/12385325#M1994388</guid>
      <dc:creator>former_member651578</dc:creator>
      <dc:date>2021-03-31T09:16:39Z</dc:date>
    </item>
  </channel>
</rss>

