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
 General SQL Server Forums
 New to SQL Server Programming
 select into an existing table

Author  Topic 

kifeda
Posting Yak Master

136 Posts

Posted - 2009-02-06 : 11:42:01
I have an existing table called tblleadmanagement. I have a new table called tblleadmanagement2. I want to copy all the date from the tblleadmanagement2 into tblleadmanagement. The fields are not identical so when I tried select * into tblleadmanagement from tblleadmanagement it didn't work.

Any suggestions? I was thinking something like select first name from tblleadmanagement2 into tblleadmanagement as strfirstname or something like that, any suggestions?

sakets_2000
Master Smack Fu Yak Hacker

1472 Posts

Posted - 2009-02-06 : 11:47:00
You'll need to read about INSERT command. Look in sql knowledge docs that come with installation.
Go to Top of Page

mapidea
Posting Yak Master

124 Posts

Posted - 2009-02-07 : 01:33:59
To copy data from one table to another you would have to first create the new table.

set identity_insert copydata on
--Set to insert the identity column
go

insert into CopyData(OrderID, OrderDate, Shipdate, CustomerID, EmpID, Ordertotal)
Select OrderID, OrderDate, Shipdate, CustomerID, EmpID, Ordertotal from orders
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-07 : 07:42:38
since column names are not identical, what you need is

INSERT INTO tblleadmanagement (Col1,Col2,Col3,...)
SELECT Col1,Col2,Col3,...
FROM tblleadmanagement2

make sure you specify columns in select corresponding to ones given in columnlist
Go to Top of Page
   

- Advertisement -