0

I'm working with SQL Server / SSIS 2005 and I am stumped on something that I believe should be a simple issue. I am trying to figure out how to insert data into another table from an incremental ID created within an SSIS project.

To help clarify, there is my example:

I have a table called users with the following values (shortened for this purpose)

User ID    Username
=======    ========
   1        jsmith
   2        jjones

I have another table called userpreferences with the following values

 ID           Keyname         Keyvalue 
=======      ===========     =========
  1          Send a Report    YES
  2          Send a Report    YES

Now that I have described the tables, I am going to be using SSIS to insert data into the users table. User ID is an identity field in the users table. ID is also an identity field in the userspreferences table. And they each correspond with each other.

What I would like to do is insert data into the userpreferences table based upon what the User ID is being generated in the users table. As an example, I insert a record through import as user ID #3. I then want to insert that ID to the user preferences table and insert the keyname and keyvalues. Just to clarify, the keyname and keyvalues are not part of the text file. I want to insert those in within the project.

Currently, I can achieve my goal through some "post processing" through T-SQL. But I am trying to do this more efficiently in SSIS. Plus this would help me a lot as I do this quite frequently.

I tried researching this and I thought this may help me: SSIS - Multiple table insert. However, the solution has the screen shots missing. Can someone assist me with this task. I would greatly appreciate it.

0

1 Answer 1

0

You could turn identity insert on your users table, and manually generate the IDs using a VB script component transformation, so they'd be available to you in the data flow to load to the user preferences table. Post processing is probably your best option here though - just build an Execute SQL task to run after the data flow completes and it will all still be part of your package.

2
  • Thank you for your reply. You are right about post-processing being easier. I got a question for you though. If I add an execute SQL task, how would I get all the ID's I already imported? Or are you saying that I would need to calculate that prior to the import and just place it there? Sep 5, 2014 at 20:51
  • I was thinking you have some kind of logic which figures out what to put on the preferences table based on some data in the users record that you are loading? Can't you just do a SQL statement to do a set-based insert into this table after the load?
    – N West
    Sep 8, 2014 at 14:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.