alter TRIGGER [GF_BOM插入记录]
ON [dbo].[t_bominserted]
FOR update
AS
SET ANSI_WARNINGS OFF
declare @FID int,@FMultiCheckStatus int,@FOldStatus int
select @FID = FID,@FMultiCheckStatus = FMultiCheckStatus from inserted
select @FOldStatus = FMultiCheckStatus from deleted
if update (FMultiCheckStatus) and @FOldStatus = 4 and @FMultiCheckStatus = 16 --单据审核时
begin
insert into icbomchild (FBRNO,FEntryID,FinterID,FitemID,Fauxqty,Fqty,Fscrap,Fopersn,Foperid,FMaterielType,FMarshalType,
Fpercent,Fbeginday,Fendday,Foffsetday,FbackFlush,FspID,Fsupply,FunitID)
select 0,t2.FMaxEntryID + b.Findex,a.FID_SRC1,b.FitemID,1,1,0,0,0,371,385,100,'1900-01-01 00:00:00.000','2100-01-01 00:00:00.000',
0,1059,0,0,b.FunitID from t_bominserted a
inner join t_bominsertedentry b on a.FID= b.FID
inner join icbom t1 on a.FID_SRC1 = t1.FinterID
inner join (select FinterID,max(FEntryID) as FMaxEntryID from icbomchild group by FinterID) t2 on t1.FinterID = t2.FinterID
where a.FID = @FID
end