赋值后,也还是不行啊
CREATE TRIGGER tigInMaterialIN ON KC_MaterialIN
FOR INSERT
AS
update KC_MaterialStock set Quantity=KC_MaterialStock.Quantity+tem.Quantity ,LastPurchaseDate = tem.Indate ,LastDeliveryDate='',SafeStock=500 from
(select MaterialID, Quantity ,Indate from inserted ) tem where tem.MaterialID=KC_MaterialStock.MaterialID
insert KC_MaterialStock select MaterialID, Quantity,Indate as LastPurchaseDate ,LastDeliveryDate='',SafeStock=500
from inserted where MaterialID not in (select MaterialID from KC_MaterialStock)
group by MaterialID
go
CREATE TRIGGER tigInMaterialIN ON KC_MaterialIN
FOR INSERT
AS
update KC_MaterialStock set Quantity=KC_MaterialStock.Quantity+tem.Quantity ,LastPurchaseDate = tem.Indate from
(select MaterialID, Quantity ,Indate from inserted ) tem where tem.MaterialID=KC_MaterialStock.MaterialID
insert KC_MaterialStock select MaterialID, Quantity,Indate as LastPurchaseDate
from inserted where MaterialID not in (select MaterialID from KC_MaterialStock)
group by MaterialID
go
CREATE TRIGGER tigInMaterialIN ON KC_MaterialIN
FOR INSERT
AS
update KC_MaterialStock set
Quantity=KC_MaterialStock.Quantity+tem.Quantity ,
KC_MaterialStock.LastPurchaseDate = tem.Indate
from inserted tem where tem.MaterialID=KC_MaterialStock.MaterialID
insert KC_MaterialStock (MaterialID,Quantity,LastPurchaseDate) select MaterialID,sum(Quantity),max(Indate)
from inserted where MaterialID not in (select MaterialID from KC_MaterialStock) group by MaterialID
go
CREATE TRIGGER 名1 ON 入库表
FOR update
AS
update 库存表 set 库存数量=库存数量-tem.数量 from (select 商品编号,sum(数量) 数量 from deleted) tem where tem.商品编号=库存表.商品编号
update 库存表 set 库存数量=库存数量+tem.数量 from (select 商品编号,sum(数量) 数量 from inserted) tem where tem.商品编号=库存表.商品编号
go
CREATE TRIGGER 名1 ON 入库表
FOR INSERT
AS
update 库存表 set 库存数量=库存数量+tem.数量 from (select 商品编号,sum(数量) 数量 from inserted) tem where tem.商品编号=库存表.商品编号
insert 库存表 select 商品编号,sum(数量) from inserted where 商品编号 not in (select 商品编号 from 库存表) group by 商品编号
go
CREATE TRIGGER 名1 ON 入库表
FOR INSERT
AS
update 库存表 set 库存数量=库存数量+tem.数量 from inserted tem where tem.商品编号=库存表.商品编号
insert 库存表 select 商品编号,sum(数量) from inserted where 商品编号 not in (select 商品编号 from 库存表) group by 商品编号
go