| Author |
Topic |
|
anjali66
Starting Member
23 Posts |
Posted - 2011-01-07 : 17:29:34
|
| Hello All, I am trying toselect * into newtableFROM (Select col1, col2, col3 from TableAUnionSELECT col1, col2, col3 from TableBUNIONSELECT col1, col2, col3 from TableC)an empty newTable already exits in the database. I am getting an error "Incorrect syntax near (.I am not sure what am I doing wrong.Any help will be appreciated. |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-01-07 : 17:33:01
|
1. The empty new table will be created so if it is already there then delete it.2. Your derived table needs an alias name. example: (select... union select ... union select ...) AS dt No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2011-01-07 : 17:34:02
|
Sniped by the Goddess... No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
anjali66
Starting Member
23 Posts |
Posted - 2011-01-07 : 17:37:44
|
| Thanks Webfred and Tkizer. I am new to this forum, but is their any way, I can mark the answer as the right answer so that other people can benefit from it. |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
glendcruz
Yak Posting Veteran
60 Posts |
Posted - 2011-01-07 : 21:36:52
|
quote: Originally posted by anjali66 Hello All, I am trying toselect * into newtableFROM (Select col1, col2, col3 from TableAUnionSELECT col1, col2, col3 from TableBUNIONSELECT col1, col2, col3 from TableC)an empty newTable already exits in the database. I am getting an error "Incorrect syntax near (.I am not sure what am I doing wrong.Any help will be appreciated.
drop TABLE newtablegocreate table TableA ( col1 int, col2 int, col3 int)gocreate table TableB ( col1 int, col2 int, col3 int)gocreate table TableC ( col1 int, col2 int, col3 int)goselect * into newtableFROM (Select col1, col2, col3 from TableAUnionSELECT col1, col2, col3 from TableBUNIONSELECT col1, col2, col3 from TableC)t --- note the aliasDROP table TableA GODROP table TableB GODROP table TableC GO-----------------------(0 row(s) affected) |
 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
|