I think I already know the answer but…
Given this statement:
Insert Into Allergy (Name, Category, Composition)
Select Name, Category, Composition
From ETVault Where Strain In (6, 2, 4)
Is it possible to get the identities that were inserted?
I understand I can break this into multiple statements and capture scope_identity() after each but that’s not what I’m asking.
The first way I thought of doing this is to use a
AFTER INSERT TRIGGERon the table, capture the entire rowset inserted, and get the identities from there.EDIT Of course, you can do this by capturing OUTPUT (doh)
http://msdn.microsoft.com/en-us/library/ms177564.aspx
Here is a working sample, Since you hadn’t provided sample data, I created my own Allery and ETVault tables, so use the example in a brand new database.
It gives you the output