1-- Never use @@identity or scope_identity()
2-- they can not always be relied upon
3
4DECLARE @Ids_tbl TABLE ([id] INT); -- Requires table. use variable for scope
5INSERT INTO [sometable] ([ColA],[ColB])
6OUTPUT INSERTED.ID INTO @Ids_tbl(id)
7VALUES ('valA','valB');
8
9SELECT [id] FROM @Ids_tbl; -- <-- Id(s) in here
10
11