jeudi 21 janvier 2016

SCope_Identity multiple insert

How can I avoid these type can I capture value for each identity insert and insert in other table

Insert into LookupTables (a, b, c, d, e, OtherInfo, SortOrder)
Values (a, b, c, d, e, NULL, NULL)

DECLARE @LookupID INT = SCOPE_IDENTITY() 

Insert into LookupTables (a, b, c, d, e, OtherInfo, SortOrder)
Values (a, b, c, d, e, @LookupID, NULL)

Insert into LookupTables (a, b, c, d, e, OtherInfo, SortOrder)
Values (a, b, c, d, e, NULL, NULL)

DECLARE @LookupID2 INT = SCOPE_IDENTITY() 

Insert into LookupTables (a, b, c, d, e, OtherInfo, SortOrder)
Values (a, b, c, d, e, @LookupID2, NULL)

Aucun commentaire:

Enregistrer un commentaire