Welcome! and rules
Joel on Software
@@Identity in Transactions
If I do the following:
Specific to your transaction, otherwise it wouldn't be much use. It will only give the result you expect if there are no triggers defined: you might want to use SCOPE_IDENTITY or IDENT_CURRENT instead (look them up in SQL Server Books Online).
That's what I thought, and that's the functionality I'm looking for (transaction-specific). I'm not using any triggers, so they're not a factor.
It is still worth considering using SCOPE_IDENTITY even if you are not currently using triggers:
"SELECT @@Identity FROM [table]"
Another note: If you are just getting the value from a function (like @@Identity) use 'Set' instead of Select. It performs faster, and the compiler knows it doesn't have to create a cursor.
Fog Creek Home