Wednesday, October 21, 2009

Copy Some Rows From Table1 to Table2 SqlServer

I am doing a one-time combining 2 separate legacy database tables that contain some of the same info but also additional different info into one new SqlServer table. I am also copying some but not all of that additional data.

So I am inserting some of the columns from each table into some of the columns in the new table.

If all the columns in table2 are going to be inserted into table1 and the column names are the same I can:

insert into table1 (Detail, Unitname, Sortorder) select * from table2

if there is a change in column name change:

insert into table1 (Detail, Unitname , Sortorder) select facilabbr as Detail, Unitname , Sortnum as Sortorder from table2

No comments:

Post a Comment