27,579
社区成员
发帖
与我相关
我的任务
分享
--存储过程创建语法...
begin tran
select a.listid,b.productid
from IM_Out a join IM_OutDetail b on a.id = b.out_id
where a.id = ?
and not exists (select 1 from IM_Stock where warehouseid = a.warehouseid
and product_id = b.product_id and quantity >= b.quantity)
if @@rowcount > 0
begin
commit tran
return
end
else
begin
--update 更新库存量
update c
set c.quantity = c.quantity - b.quantity
from IM_Out a join IM_OutDetail b on a.id = b.out_id
join IM_Stock c on a.warehouseid = c.warehouseid and b.product_id = c.product_id
where a.id = ?
commit tran
end