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
 Site Related Forums
 Article Discussion
 Article: Keeping Data in Temp Tables
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

AskSQLTeam
Ask SQLTeam Question

USA
0 Posts

Posted - 08/18/2000 :  18:08:51  Show Profile  Visit AskSQLTeam's Homepage  Reply with Quote
Chris writes "Hi, I have several tables I would like to select into a temporary table . . . As you might know everytime I try a new Select into the #TempTable loses the data already in it. What can I do to preserve the #TempTable data?"

Article Link.

Anonymous
Starting Member

0 Posts

Posted - 08/21/2000 :  07:39:47  Show Profile  Reply with Quote
Try using a UNION

If all the tables you want to copy have the same columns, you could use the UNION clause in the select statement

Go to Top of Page

Anonymous
Starting Member

0 Posts

Posted - 01/12/2001 :  18:29:31  Show Profile  Reply with Quote
Using temporary tables

To make the entire process clear for yourself, treat a temporary table just like any other table. The only difference is it's prefixed with a #.
So to begin use a CREATE TABLE statement.
CREATE TABLE #testTemp(
temp_id IDENTITY(1,1) PRIMARY KEY CLUSTERED,
field1 varchar(255),
field2 int)

INSERT INTO #testTemp(field1,field2)
SELECT a.field1, a.field2
FROM a

INSERT INTO #testTemp(field1,field2)
SELECT b.field1, b.field2
FROM b

Not only you can insert into temporary tables, you can update them,
delete from them, etc.


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