SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Results of Union into Temp Table
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

MJ1210
Starting Member

3 Posts

Posted - 04/03/2008 :  16:10:16  Show Profile  Reply with Quote
This may be a dumb question, but I can't seem to get the syntax right. I have two temp tables that have the same columns, I want to do a union on them and store the results in a temp table. Any ideas?

Ie.

select * from #tmpTable1
union
select * from #tmpTable2
into #tmpTable3

Thanks!!!

sodeep
Flowing Fount of Yak Knowledge

USA
7174 Posts

Posted - 04/03/2008 :  16:12:59  Show Profile  Reply with Quote
create # table(col.....)
go

insert into #table
select * from #tmpTable1
union
select * from #tmpTable2

Edited by - sodeep on 04/03/2008 16:14:34
Go to Top of Page

MJ1210
Starting Member

3 Posts

Posted - 04/03/2008 :  16:20:56  Show Profile  Reply with Quote
Thanks! So this will put it in a local temp table (ie. the temp table will be deleted when stored procedure is done executing?)

Thanks so much!
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22744 Posts

Posted - 04/04/2008 :  02:17:14  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
or

Select * into #tmpTable3 from
(
select * from #tmpTable1
union
select * from #tmpTable2
) as t

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

India
22744 Posts

Posted - 04/04/2008 :  02:18:43  Show Profile  Send madhivanan a Yahoo! Message  Reply with Quote
quote:
Originally posted by MJ1210

Thanks! So this will put it in a local temp table (ie. the temp table will be deleted when stored procedure is done executing?)

Thanks so much!


If you create a temp table in a procedure, it would be dropped automatically once it is executed

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000