Prev: What is the best way to write a sp to insert a row having more than 200 columns?
Next: SqlTransaction Problem
From: Roy Goldhammer on 12 Jul 2010 05:06 Hello there. I have two tables i need to insert table2 to table1. the field: ID (unique identity) on table2 exist already on table1. So i need insert the data to table1 and get new identity for each rows and get table of the new identity vs old identity: for examlple vstable old_iden, new_iden 5 , 12 6, 13 7, 14 I've tried to do it with output but it can't give me the old ID. is there a way to do this without doing it one by one?
From: Philipp Post on 12 Jul 2010 05:17
> I've tried to do it with output but it can't give me the old ID. is there a way to do this without doing it one by one? < You could create a column "old_id" in the new table, then insert the old table data into the new one INSERT INTO new_table(old_id, -- other columns ) SELECT id, -- other columns FROM old_table; Alternatively you could watch out for a primary key without using IDENTITY to get rid of this, i.e. some data standard. brgds Philipp Post |