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.
| Author |
Topic |
|
tiwas
Starting Member
37 Posts |
Posted - 2012-02-02 : 10:48:13
|
| Hi,I need to transfer a customer's old user db to my new db. The old was a flat file structure (db2) and in order to make it more flexible I need to split it up into several.So...I exported the db to csv and then imported it into ms sql 2008 using bulk import.Now, the next step is importing the user details from the old structure into the new one. This is fairly easy. However, there are data in the old one I need to reference in order to fill the other tables. When inserting into the new they will get an id (primary key int) and I would like to put this into the old file as reference.Is there a way to do this? I guess the base query would be something likeinsert into newTable(firstname, lastname) select first_name, last_name from oldTableThe return from this would be the identity - but how do I pick it up and insert it into the same row in oldTable?Cheers! |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
|
|
tiwas
Starting Member
37 Posts |
Posted - 2012-02-02 : 13:31:46
|
| To be honest, I didn't really understand that at all. :SIsn't it possible to do some foreach-magic? I've added a column for id to the imported db2 table. If I could just do something likeforeach (@id in select col_id from table) { select * from table where col_id = @id -- insert what I need into the users table, get user_col_id -- insert into other tables using the user_col_id value -- insert user_col_id value into the original db}Isn't this possible in sql? |
 |
|
|
tiwas
Starting Member
37 Posts |
Posted - 2012-02-02 : 13:35:33
|
| I might be able to use something like this? -> http://weblogs.asp.net/jgalloway/archive/2006/04/12/442618.aspx |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-02-02 : 13:36:12
|
| the solution you're proposing does row by row iteration which will not perform as much as set based solution i gave you.suggest you to first have a look at OUTPUT caluse to understand how it workshttp://msdn.microsoft.com/en-us/library/ms177564.aspx------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2012-02-02 : 14:25:53
|
| SSIS has facilities to do transformations of this nature. |
 |
|
|
|
|
|