In SSIS, How do I use the execute SQL task to insert a single row with no parameters and get the primary key back so I can set it to user variable? My insert query is simply:
INSERT INTO [AdWords.ImportData] (EndDate) VALUES (null)
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Good question, took me a few tries to figure it out. Declare an SSIS variable of type Int32 (unless you need sizing for a bigint or numeric). I chose tablePk as mine.
Option 1
Execute SQL Task
ResultSet: None
SQL
Variable Name: User::tablePk
Direction: Output
Data Type: Long
Parameter Name: 0
Parameter Size: -1
Option 2
This was the original solution as I couldn’t grok how to get the placeholder
?in a normal query. It couldn’t as simple as what I had above, except it was.The only difference is the query used
SQL
Option 3
If you’re using a data flow, I outline an approach on How to Add the Result Set from a T-SQL Statement to a Data Flow? In short, you need to add a column into the data flow prior to an OLE DB Command. Within the OLE DB Command, you will map that empty column into a
OUTPUTparameter from your stored procedure and then as the stored procedure fires, it will replace the column with the value from the procedure.