Audit Success trigger, is a typical scene. You need to use the update trigger, tracking the approval status changes.
Reference source "after the anti-Purchase Inspection audit write receipt notice", which is BOS Purchase Inspection custom documents.
IF (object_id ( 'bobang_tgr_check_update', 'TR') IS not null) drop the Trigger bobang_tgr_check_update Go the Create the Trigger cl_tgr_check_update ON bobang_bos_check the After Update AS DECLARE @FID int DECLARE @FMultiCheckStatus VARCHAR (100) DECLARE @FAuxQtyPass float - the number of qualified declare @FQtyPass float - the basic unit of the number of qualified declare @FAuxNotPassQty float - the number of failed declare @FNotPassQty float - the basic unit of the number of failed declare @FAuxConPassQty float - the number of concession declare @FConPassQty float - the basic unit of concessions to the number of receivers declare @FID_Src bigint - single source ID DECLARE @FEntryID_SRC bigint - single source FEntryID SELECT the FID = the FID @, @ = FMultiCheckStatus FMultiCheckStatus from inserted The --审核时 if update(FMultiCheckStatus) and @FMultiCheckStatus=16 begin declare mycursor cursor for select FAuxPassQty,FPassQty,FAuxUnPassQty,FUnPassQty,FAuxConcessQty,FConcessQty,FID_Src,FEntryID_Src from bobang_bos_checkentry where FID=@FID open mycursor fetch next from mycursor into @FAuxQtyPass,@FQtyPass,@FAuxNotPassQty,@FNotPassQty,@FAuxConPassQty,@FConPassQty,@FID_Src,@FEntryID_SRC while (@@fetch_status=0) begin update t1 set t1.FAuxQtyPass=t1.FAuxQtyPass+isnull(@FAuxQtyPass,0), t1.FQtyPass=t1.FQtyPass+isnull(@FQtyPass,0), t1.FAuxNotPassQty=t1.FAuxNotPassQty+isnull(@FAuxNotPassQty,0), t1.FNotPassQty=t1.FNotPassQty+isnull(@FNotPassQty,0), t1.FAuxConPassQty=t1.FAuxConPassQty+isnull(@FAuxConPassQty,0), t1.FConPassQty=t1.FConPassQty+isnull(@FConPassQty,0) from POInStockEntry t1 left join POInStock t2 on t1.FInterID=t2.FInterID where t1.FInterID=@FID_Src and t1.FEntryID=@FEntryID_SRC and t2.FTranType=72 fetch next from mycursor into @FAuxQtyPass,@FQtyPass,@FAuxNotPassQty,@FNotPassQty,@FAuxConPassQty,@FConPassQty,@FID_Src,@FEntryID_SRC end close mycursor DEALLOCATE mycursor end --驳回前检查 declare @isTuiLiao int declare @isRuKu int if update(FMultiCheckStatus) and @FMultiCheckStatus=4 begin declare mycursor cursor for select FAuxPassQty,FPassQty,FAuxUnPassQty,FUnPassQty,FAuxConcessQty,FConcessQty,FID_Src,FEntryID_Src from bobang_bos_checkentry where FID=@FID open mycursor fetch next from mycursor into @FAuxQtyPass,@FQtyPass,@FAuxNotPassQty,@FNotPassQty,@FAuxConPassQty,@FConPassQty,@FID_Src,@FEntryID_SRC while (@@fetch_status=0) begin select @isTuiLiao=COUNT(*) from POInStockEntry where FSourceTrantype=72 and FSourceInterId=@FID_Src and FSourceEntryID=@FEntryID_SRC if @isTuiLiao>0 begin raiserror ( 'pushdown stripper notice has not de-approved!', 16,1) ROLLBACK Tran End SELECT @ isRuKu = COUNT (*) from ICStockBillEntry WHERE FSourceTrantype = 72 and FSourceInterId = @ = @ FEntryID_SRC FID_Src and FSourceEntryID IF @ isTuiLiao> 0 the begin RAISERROR ( 'Purchase Receipt has been pushed down, can not be de-approved!', 16,1) ROLLBACK Tran End FETCH from the Next MyCursor INTO @ FAuxQtyPass, @ FQtyPass, @ FAuxNotPassQty, @ FNotPassQty, @ FAuxConPassQty, @ FConPassQty, @ FID_Src, @ FEntryID_SRC End use Close MyCursor DEALLOCATE MyCursor End - initially dismissed if update(FMultiCheckStatus) and @FMultiCheckStatus=2 begin declare mycursor cursor for select FAuxPassQty,FPassQty,FAuxUnPassQty,FUnPassQty,FAuxConcessQty,FConcessQty,FID_Src,FEntryID_Src from bobang_bos_checkentry where FID=@FID open mycursor fetch next from mycursor into @FAuxQtyPass,@FQtyPass,@FAuxNotPassQty,@FNotPassQty,@FAuxConPassQty,@FConPassQty,@FID_Src,@FEntryID_SRC while (@@fetch_status=0) begin update t1 set t1.FAuxQtyPass=t1.FAuxQtyPass-isnull(@FAuxQtyPass,0), t1.FQtyPass=t1.FQtyPass-isnull(@FQtyPass,0), t1.FAuxNotPassQty=t1.FAuxNotPassQty-isnull(@FAuxNotPassQty,0), t1.FNotPassQty=t1.FNotPassQty-isnull(@FNotPassQty,0), t1.FAuxConPassQty=t1.FAuxConPassQty-isnull(@FAuxConPassQty,0), t1.FConPassQty=t1.FConPassQty-isnull(@FConPassQty,0) from POInStockEntry t1 left join POInStock t2 on t1.FInterID=t2.FInterID where t1.FInterID=@FID_Src and t1.FEntryID=@FEntryID_SRC and t2.FTranType=72 fetch next from mycursor into @FAuxQtyPass,@FQtyPass,@FAuxNotPassQty,@FNotPassQty,@FAuxConPassQty,@FConPassQty,@FID_Src,@FEntryID_SRC end close mycursor DEALLOCATE mycursor end