Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > microsoft.public.sqlserver.programming > #31373

Re: [SAP B1] create a VIEW with UNION and WHILE

From Erland Sommarskog <esquel@sommarskog.se>
Newsgroups microsoft.public.sqlserver.programming
Subject Re: [SAP B1] create a VIEW with UNION and WHILE
Date 2021-03-31 22:32 +0200
Organization Erland Sommarskog
Message-ID <XnsACFEE5428854AYazorman@127.0.0.1> (permalink)
References <XnsACFE7390C25D5ammammatatiscalineti@127.0.0.1>

Show all headers | View raw


Ammammata (ammammata@tiscalinet.it) writes:
> 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).
> 
> The SQL is like this:
> 
> SELECT *
> INTO #tmp

That's not a good start for a view. A view is a single SELECT statement.

It seems that this should make it for you:

CREATE VIEW yourview AS
SELECT a,b,c
FROM tableONE
UNION ALL
SELECT a,b,c
FROM tableTWO
UNION ALL
SELECT a,b,c
FROM tableTHREE
UNION ALL
SELECT a,b,c
FROM tableFOUR
UNION ALL
select a,b,V.n as c
from tableFIVE
cross join (VALUES(1), (2), (3), (4), (5), (6), (7), 
                 (8), (9), (10), (11), (12), (13)) AS V(n)


THe error message "unable to parse" sounds like you are using the view
designer. Stay out of that tool, it's quite crippled and may not parse 
the above either. Just run the above in a query window.

Back to microsoft.public.sqlserver.programming | Previous | NextPrevious in thread | Next in thread | Find similar


Thread

[SAP B1] create a VIEW with UNION and WHILE Ammammata <ammammata@tiscalinet.it> - 2021-03-31 09:21 +0000
  Re: [SAP B1] create a VIEW with UNION and WHILE Erland Sommarskog <esquel@sommarskog.se> - 2021-03-31 22:32 +0200
    Re: [SAP B1] create a VIEW with UNION and WHILE Ammammata <ammammata@tiscalinet.it> - 2021-04-06 08:15 +0000
      Re: [SAP B1] create a VIEW with UNION and WHILE Ammammata <ammammata@tiscalinet.it> - 2021-04-06 15:19 +0000
        Re: [SAP B1] create a VIEW with UNION and WHILE Ammammata <ammammata@tiscalinet.it> - 2021-04-06 15:22 +0000
          Re: [SAP B1] create a VIEW with UNION and WHILE Ammammata <ammammata@tiscalinet.it> - 2021-04-06 15:45 +0000
            Re: [SAP B1] create a VIEW with UNION and WHILE Doc Tree <davidleerothshairpiece@gmail.com> - 2023-09-02 20:14 -0700

csiph-web