viernes, 11 de diciembre de 2015

Get Inserted Primary Key ID in SQL

DECLARE @InsertedId TABLE ( Id INT )

INSERT INTO bsc.tm_ibo_items_book  ( <fields> )
OUTPUT INSERTED.Id INTO @InsertedId
SELECT TOP 1 col1, col2 FROM Table1

Called as:

SET @Id = SELECT TOP 1 Id FROM @InsertedId