日期:2014-05-18 浏览次数:20703 次
--存储过程创建语法...
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
------解决方案--------------------
if (查找库存的数量)> 0
begin
if 查找库存的数量 >要出货的数量
begin
update 库存表
set 库存数量 = 库存数量 - 要出货的数量
where 出货单 = 传入参数
insert into 库存记录表
select 出货单,要出货的数量,进出类型标记
end
else
begin
RAISERROR('库存有,但是不足出货', 18, 1)
end
end
else
begin
RAISERROR('库存为0', 18, 1)
end