June 22, 2009 at 9:13 am
I need to retrieve a set of rows from one table and insert these into another table. The column names are different between the 2 tables and It needs to be in a stored procedure (inside a transaction)
can anyone point me in the right direction ? I need something like
SELECT columns from table A Into columns in table B
June 22, 2009 at 9:17 am
select collist into NewTable from OldTable is the right syntax.
Ref. http://msdn.microsoft.com/en-us/library/ms188029.aspx%5B/URL%5D
June 22, 2009 at 9:20 am
I'm older school, but I'd go with
create proc
insert b (colA, colb, colc)
select otherColA, otherColb, otherColC
from a
return
June 22, 2009 at 9:22 am
Actually, if the target table already exists, you need to run an insert select statement. Something like this:
Insert into TargetTable (col1, col3)
Select colA, ColB
From target server
For more information I suggest that you’ll read BOL (Books On Line – the help file that comes with SQL Server) about the subject “Adding Rows by Using INSERT and SELECT”
Adi
--------------------------------------------------------------
To know how to ask questions and increase the chances of getting asnwers:
http://www.sqlservercentral.com/articles/Best+Practices/61537/
For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply