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 2005 Forums
 Transact-SQL (2005)
 Copying columns

Author  Topic 

nmarks
Yak Posting Veteran

53 Posts

Posted - 2007-10-10 : 05:33:15
How can I copy a column of data from table into another.

One table is full of data, the other is entirely empty and both tables have identical structures.

How can this be done quickly?

Answers much appreciated.

nmarks
Yak Posting Veteran

53 Posts

Posted - 2007-10-10 : 05:39:04
Fixed it. Thanks for reading though.
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-10-10 : 05:39:16
[code]Insert into Dest_Table(Col1, col2, col3...)
Select
Col1, col2, col3...
from Source_Table[/code]

Note: Assuming both tables belong to same database.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-10-10 : 05:39:48
You mean UPDATE?

Column X in TableB is empty (all values are NULL) and you have correct values in TableA?


UPDATE b
SET b.ColX = a.Col1
FROM TableB AS b
INNER JOIN TableA AS a ON a.PK = b.PK



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

QuachNguyen
Starting Member

15 Posts

Posted - 2007-10-10 : 13:03:12
quote:
Originally posted by harsh_athalye

Insert into Dest_Table(Col1, col2, col3...)
Select
Col1, col2, col3...
from Source_Table


Note: Assuming both tables belong to same database.

Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"



Hi harsh_athalye

Your statement is work fine , It's new for me , but when I try to insert with identity column , I got the duplicate record message .And cannot insert to destination table .

How can I do this with table that having identity column ?

Thanks in advance .
Sorry for poor english .

Go to Top of Page

cognos79
Posting Yak Master

241 Posts

Posted - 2007-10-10 : 13:54:32
dont include the indentify column in the insert statement.
Go to Top of Page
   

- Advertisement -