IF EXISTS (select name from sysobjects where name='tr_即时库存' and xtype='tr')
DROP TRIGGER tr_即时库存
GO
CREATE TRIGGER tr_即时库存 ON ICInventory
FOR INSERT,UPDATE,DELETE
AS
update t1 set t1.F_102=t2.FQty
from t_ICItemCustom t1
inner join (select t1.FItemID,t1.FBatchNo,sum(t1.FQty) as FQty
from ICInventory t1
where t1.FItemId in(select FItemID from inserted ) and t1.FQty<>0
group by t1.FItemID,t1.FBatchNo) t2 on t1.FItemID=t2.FItemid
IF EXISTS (select name from sysobjects where name='tr_即时库存icitem' and xtype='tr')
DROP TRIGGER tr_即时库存icitem
CREATE TRIGGER tr_即时库存icitem ON t_ICItem
FOR INSERT,UPDATE
AS
update t1 set t1.F_102=t2.FQty
from t_ICItemCustom t1
inner join (select t1.FItemID,t1.FBatchNo,sum(t1.FQty) as FQty
from ICInventory t1
where t1.FItemId in(select FItemID from inserted ) and t1.FQty<>0
group by t1.FItemID,t1.FBatchNo) t2 on t1.FItemID=t2.FItemid