Getting the Id of a row I updated in Sql Server

前端 未结 4 759
别那么骄傲
别那么骄傲 2020-12-01 10:27

I\'m trying to return the Id of a row I update in sql

UPDATE ITS2_UserNames
  SET AupIp = @AupIp
  WHERE @Customer_ID = TCID AND @Handle_ID = ID

  SELECT @         


        
4条回答
  •  甜味超标
    2020-12-01 11:28

    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
    

提交回复
热议问题