USE [AIS20221128142101]
GO
/****** Object: Trigger [dbo].[wsd_install_status_update] Script Date: 2023-01-07 14:11:09 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO--安装费关闭状态触发器
/*查询单据体安装费关闭状态(字段:FInteger1),若状态为1(关闭状态),再查询单据体调试费关闭状态(字段:FDecimal4),若此状态为0,修改安装费田试状态为0
*/ALTER TRIGGER [dbo].[wsd_install_status_update] ON [dbo].[wsd_hkdjtz_mx]
FOR UPDATE
AS
BEGINSET NOCOUNT ONif update(FInteger1) or update(FDecimal4) --监控两个字段begin declare @FID intdeclare @FEntryID intdeclare @FInteger1 int --安装费关闭状态declare @FDecimal4 int --调试费关闭状态declare @FAmount6 decimal(20,6) --应付安装费declare @FAmount4 decimal(20,6) --已付安装费declare cur cursor for select FID, FEntryID, FInteger1, FDecimal4,FAmount6,FAmount4 from Insertedopen curfetch next from cur into @FID, @FEntryID, @FInteger1, @FDecimal4, @FAmount6, @FAmount4while @@FETCH_STATUS = 0beginif @FInteger1 = 1 --监控安装费关闭状态:安装费关闭状态计划变为1时,判断调试费关闭状态,若为0,将安装费关闭状态计划变为 0beginif 0 = ( select FDecimal4 from wsd_hkdjtz_mx where FEntryID = @FEntryID and FID = @FID )beginupdate wsd_hkdjtz_mx set FInteger1 = 0 where FEntryID = @FEntryID and FID = @FIDendendif @FDecimal4 = 1 --监控调试费关闭状态:调试费关闭状态计划变为1时,判断(应付安装费-已付安装费)是否为0,若为零,将安装费关闭状态计划变为 1beginif 0 = ( select (FAmount6 - FAmount4 ) from wsd_hkdjtz_mx where FEntryID = @FEntryID and FID = @FID )beginupdate wsd_hkdjtz_mx set FInteger1 = 1 where FEntryID = @FEntryID and FID = @FIDendendfetch next from cur into @FID, @FEntryID, @FInteger1, @FDecimal4, @FAmount6, @FAmount4endclose curdeallocate curend
END