Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Help! Why this query does not work

Author  Topic 

mavershang
Posting Yak Master

111 Posts

Posted - 2008-10-16 : 00:49:19
I am new to SQL. Here is my query:

SELECT *
INTO NewTable
FROM ( SELECT COL1,COL2 FROM Table1
UNION ALL
SELECT COL3,COL4 FROM Table2)

It fails. The query in the bracket works independently. I am wondering why the overall query does not work, and how to make it work.

Thanks.

afrika
Master Smack Fu Yak Hacker

2706 Posts

Posted - 2008-10-16 : 00:59:06
[code]
insert INTO NewTable
(col1, col2)
SELECT COL1,COL2 FROM Table1
UNION ALL
SELECT COL3,COL4 FROM Table2[/code]
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-16 : 01:45:30
quote:
Originally posted by mavershang

I am new to SQL. Here is my query:

SELECT *
INTO NewTable
FROM ( SELECT COL1,COL2 FROM Table1
UNION ALL
SELECT COL3,COL4 FROM Table2)t

It fails. The query in the bracket works independently. I am wondering why the overall query does not work, and how to make it work.

Thanks.


put an alias for derived table and try
Go to Top of Page

mavershang
Posting Yak Master

111 Posts

Posted - 2008-10-16 : 11:15:33
I did it using your strategy.
Thanks a lot for all your help.




quote:
Originally posted by afrika


insert INTO NewTable
(col1, col2)
SELECT COL1,COL2 FROM Table1
UNION ALL
SELECT COL3,COL4 FROM Table2


Go to Top of Page
   

- Advertisement -