对啊,先UPDATE 后在INSERT了,分两条语句 CREATE TRIGGER [updateday] ON [dbo].[Material] FOR UPDATE AS if update(stuff) or update(manpower) or update(produce) or update(process) begin update material set editstan=case when standard=0 then getdate() else editstan end, standday=case when standard=0 then getdate() else standday end, standard=stuff+manpower+produce+process insert costhist(goodsid,stuff,manpower,process, produce,editstan,costtime,wastage) select idno,stuff,manpower,process,produce, getdate(),costtime,wastage from inserted where ifset = 0 end
不用CASE吧?
CREATE TRIGGER [updateday] ON [dbo].[Material]
FOR UPDATE
AS
if update(stuff) or update(manpower) or update(produce) or update(process)
begin
update material
set editstan=case when standard=0 then getdate()
else editstan end,
standday=case when standard=0 then getdate() else standday end,
standard=stuff+manpower+produce+process insert costhist(goodsid,stuff,manpower,process,
produce,editstan,costtime,wastage)
select idno,stuff,manpower,process,produce,
getdate(),costtime,wastage
from inserted where ifset = 0
end