|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Insert into table with union?Hello
I was wondering howto insert into a new table with a union query, something like: SELECT * INTO #New FROM SELECT SomeNmbr FROM #A UNION SELECT SomeNmbr FROM #A Hi Lasse,
SELECT * INTO #New FROM ( SELECT SomeNmbr FROM #A UNION SELECT SomeNmbr FROM #A ) UnionQuery HTH, jens Suessmeyer. Jens,
one problem :) If I do it like this: SELECT * INTO #New FROM ( SELECT A FROM #A UNION SELECT B FROM #A ) UnionQuery the column in #New has no name, how i specify it? Show quote "Jens" <J***@sqlserver2005.de> wrote in message news:1137145010.005733.42990@g43g2000cwa.googlegroups.com... > Hi Lasse, > > SELECT * INTO #New FROM > ( > SELECT SomeNmbr FROM #A > UNION > SELECT SomeNmbr FROM #A > ) UnionQuery > > HTH, jens Suessmeyer. > First of all , try to eliminate the * in your productional code, and
name the first resultset in the UNION Query (which give the name for the following resultsets) if it is not named by the choosen columnname (like in a expression)) Create Table #A ( SomeColumnA INT, SomeColumnB INT ) SELECT SomeColumnA INTO #New FROM ( SELECT SomeColumnA FROM #A UNION SELECT SomeColumnB FROM #A ) UnionQuery Select * from #new SomeColumnA ----------- HTH, jens Suessmeyer. |
|||||||||||||||||||||||