If else in stored procedure sql server

后端 未结 8 1664
孤街浪徒
孤街浪徒 2021-02-02 07:19

I have created a stored procedure as follow:

Create Procedure sp_ADD_USER_EXTRANET_CLIENT_INDEX_PHY
(
@ParLngId int output
)
as
Begin
    SET @ParLngId = (Select         


        
8条回答
  •  醉酒成梦
    2021-02-02 07:22

    if not exists (select dist_id from tbl_stock where dist_id= @cust_id and item_id=@item_id)
        insert into tbl_stock(dist_id,item_id,qty)values(@cust_id, @item_id, @qty); 
    else
        update tbl_stock set qty=(qty + @qty) where dist_id= @cust_id and item_id= @item_id;
    

提交回复
热议问题