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
Alternatively to bilinkc's version, without parameters:
Execute SQL Task
General tab ResultSet: Single Row
SQL
INSERT INTO dbo.ImportData (EndDate) VALUES (NULL);
SELECT SCOPE_IDENTITY() AS LastId
In the mapping of the single-row result set, enter LastId in the result name box, and map to your variable.
May well be marginally faster with a single output parameter (bilinkc's version), depends on how SSIS does it 'under the covers' and whether it creates a full datareader versus a single sp_ExecuteSQL call with output parameter.