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
 SQL Server 2008 Forums
 Transact-SQL (2008)
 union to do select into

Author  Topic 

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2011-11-21 : 11:42:43
how can I do a select union from a table into a temp table on the fly...
The following sql does not work. Can you see what I am doing wrong please? Thanks
i.e.
select field1, field2 rom tbl1
union All
select field1, field2 from tbl2
into
#tblTempData

Thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-21 : 11:46:25
[code]
select *
into #tblTempData
from
(select field1, field2 from tbl1
union All
select field1, field2 from tbl2
)t
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

DP978
Constraint Violating Yak Guru

269 Posts

Posted - 2011-11-21 : 14:40:33
Also

Select
Field1, Field2
Into #tblTempData
From tbl1
Union All
Select Field1, Field2
From tbl2
Go to Top of Page

arkiboys
Master Smack Fu Yak Hacker

1433 Posts

Posted - 2011-11-21 : 17:08:57
Thank you
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-22 : 01:13:28
wc

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -