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 2000 Forums
 SQL Server Development (2000)
 Query how can i upload table2 data into table1

Author  Topic 

reddymade
Posting Yak Master

165 Posts

Posted - 2006-05-25 : 15:44:02
I have two tables table1 and table2, both has same columns everything same.
the first column in both the tables is ID which is a idnetity true column with increments 1.

Can you please tell me, I am looking for a query how to upload the data from table2 into table1. except the id column since it is an identity column.

Please help, thank you very much for the information.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-05-25 : 15:49:18
UPDATE t1
SET Column1 = t2.Column1, Column2 = t2.Column2, ...
FROM Table1 t1
INNER JOIN Table2 t2
ON t1.[ID] = t2.[ID]

Tara Kizer
aka tduggan
Go to Top of Page

reddymade
Posting Yak Master

165 Posts

Posted - 2006-05-25 : 16:16:34
Hello Tara,
I have 50K records in table1 and 30K records in table two, when i execute the above statement i want the total to become 80K.

I see the above statement is using the Update instead of insert statement. I am counfused can you please help.

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2006-05-25 : 16:20:31
INSERT INTO Table1 (Column1, Column2, ...) <-- exclude ID
SELECT Column1, Column2, ...
FROM Table2

Is that what you want?

Tara Kizer
aka tduggan
Go to Top of Page
   

- Advertisement -