Getting the Id of a row I updated in Sql Server

The @@identity and scope_identity() will hand you the identity of a new row, ie. after an insert. After your update, the identity of the row is… @Customer_ID or @Handle_Id? If it is a different field, you should use the OUTPUT clause to return the ID of the updated row:

UPDATE ITS2_UserNames  
SET AupIp = @AupIp  
OUTPUT INSERTED.PrimaryKeyID
WHERE @Customer_ID = TCID AND @Handle_ID = ID

Leave a Comment