Considering the following TSQL:
INSERT INTO Address(Street1, City, State, ZipCode)
SELECT Street1, City, StateCode, ZipCode
FROM Contact
The Address has an identity column that is automatically set. Is there a way to get a list of the identities of Address records newly inserted?
I know there is @@IDENTITY, but that just returns the last identity.
Assuming the identity column is called AddressID, you can:
Or:
Keep in mind
@@IDENTITYshould almost never be used. Even when dealing with single-row inserts,SCOPE_IDENTITY()is much safer. See this answer for more background.