Good question, took me a few attempts to figure it out. Declare an SS32 variable of type Int32 (unless you need calibration for bigint or numeric). I chose tablePk as mine.
Option 1
SQL task execution
ResultSet: None
SQL
INSERT INTO dbo.ImportData (EndDate) VALUES (NULL); SELECT ? = SCOPE_IDENTITY()
Variable Name: User :: tablePk
Direction: Exit
Data type: long
Parameter Name: 0
Parameter: -1
Option 2
This was an original solution, as I could not figure out how to get a placeholder ? in a regular request. It could not be as simple as what I had above, except that it was.
The only difference is the use of the query
SQL
DECLARE @sql nvarchar(500) , @paramDef nvarchar(500) SELECT @sql = N'INSERT INTO dbo.ImportData (EndDate) VALUES (NULL); SELECT @ident = SCOPE_IDENTITY();' , @paramDef = N'@ident int OUTPUT' EXECUTE sp_executesql @sql, @paramDef, @ident = ? OUTPUT
Option 3
If you use a data stream, I am describing an approach. How to add a result set from a T-SQL statement to a data stream? In short, you need to add a column to the data stream before the OLE DB command. In the OLE DB command, you map this empty column to the OUTPUT parameter from the stored procedure, and then as the stored procedure starts, it will replace the column with the value from the procedure.
billinkc
source share