销售单据关闭状态触发器 SQLserver

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 
BEGIN
	SET NOCOUNT ON
	if update(FInteger1) or update(FDecimal4)  --监控两个字段
	begin	
		declare @FID int
		declare @FEntryID int
		declare @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 Inserted
		open cur
		fetch next from cur into @FID, @FEntryID, @FInteger1, @FDecimal4, @FAmount6, @FAmount4

		while @@FETCH_STATUS = 0
		begin
			if @FInteger1 = 1 --监控安装费关闭状态:安装费关闭状态计划变为1时,判断调试费关闭状态,若为0,将安装费关闭状态计划变为 0
			begin
				if 0 = ( select FDecimal4 from wsd_hkdjtz_mx where FEntryID = @FEntryID and FID = @FID )
				begin
					update wsd_hkdjtz_mx set FInteger1 = 0 where FEntryID = @FEntryID and FID = @FID
				end
			end
			if @FDecimal4 = 1 --监控调试费关闭状态:调试费关闭状态计划变为1时,判断(应付安装费-已付安装费)是否为0,若为零,将安装费关闭状态计划变为 1
			begin
				if 0 = ( select (FAmount6 - FAmount4 ) from wsd_hkdjtz_mx where FEntryID = @FEntryID and FID = @FID )
				begin
					update wsd_hkdjtz_mx set FInteger1 = 1 where FEntryID = @FEntryID and FID = @FID
				end
			end
			fetch next from cur into @FID, @FEntryID, @FInteger1, @FDecimal4, @FAmount6, @FAmount4
		end
		close cur
		deallocate cur
	end
END

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值