开发者

getting the updated value from an UPDATE query

I have an UPDATE Query :

UPDATE   FKMS_GNST_Transaction_Details
   SET Received_Quantity=Received_Quantity+(
                       CASE
                       WHEN (@int_Updated_Qty)>=(GTD.Quantity-GTD.Received_Quantity)
        THEN GTD.Quantity-GTD.Received_Quantity
                       ELSE (@int_Updated_Qty)
                       END)
      ,@int_GNST_Reference_Id=GTD.Transaction_Detail_Id   
  FROM FKMS_GNST_Transaction_Details GTD
 INNER JOIN #tbl_transactions tmp
    ON tmp.Transaction_id=GTD.Transactio开发者_StackOverflown_id
   AND GTD.Item_id=tmp.Item_id

I want to get the quantity which is added to the Received_Quantity field. That is, if (@int_Updated_Qty)>=(GTD.Quantity-GTD.Received_Quantity) then GTD.Quantity-GTD.Received_Quantity other wise @int_Updated_Qty.

How can we take this value (into a variable or any other way)? Please help.


Use the OUTPUT clause

UPDATE   FKMS_GNST_Transaction_Details
   SET Received_Quantity=Received_Quantity+(
                       CASE
                       WHEN (@int_Updated_Qty)>=(GTD.Quantity-GTD.Received_Quantity)
        THEN GTD.Quantity-GTD.Received_Quantity
                       ELSE (@int_Updated_Qty)
                       END)
      ,@int_GNST_Reference_Id=GTD.Transaction_Detail_Id   

--start gbn code
OUTPUT INSERTED.Received_Quantity
--end gbn code

  FROM FKMS_GNST_Transaction_Details GTD
 INNER JOIN #tbl_transactions tmp
    ON tmp.Transaction_id=GTD.Transaction_id
   AND GTD.Item_id=tmp.Item_id

The OUTPUT results can go

  • into a table (real, temp or variable)
  • to the client as a recordset

You can't assigned directly to a local variable

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜