How to store sql scope_identity() in variable right after insert query in run query activity
How to get id after insertion in a variable
Thanks
How to store sql scope_identity() in variable right after insert query in run query activity
How to get id after insertion in a variable
Thanks
Welcome to the community
Can you be more elaborate on what is the ask here?
And insert query are run using execute non query generally…and select queries are run using execute query activity
Cheers
Hi @iamhamzanasir,
SCOPE_IDENTITY()
value. You can do this by clicking on the “Add Parameter” button in the Properties panel and setting the “Direction” to “Output”.SCOPE_IDENTITY()
function to retrieve the last inserted identity value. For example, your query could look like this:INSERT INTO MyTable (Column1, Column2) VALUES ('Value1', 'Value2');
SELECT SCOPE_IDENTITY();
MyVariable = Convert.ToInt32(OutputParam.Value)
This will assign the SCOPE_IDENTITY()
value to the “MyVariable” variable as an integer.