首页 > 其他分享 >触发器模板

触发器模板

时间:2023-03-31 11:55:13浏览次数:30  
标签:触发器 iID cVouchType CloseBill Ap select where 模板

--删除
if exists( select * from dbo.sysobjects where id = OBJECT_ID(N'[dbo].[trig_delete_Ap_CloseBill_extradefine]') and OBJECTPROPERTY(id,N'IsTrigger')=1)
    drop TRIGGER trig_delete_Ap_CloseBill_extradefine
go
CREATE TRIGGER trig_delete_Ap_CloseBill_extradefine
   ON  Ap_CloseBill_extradefine 
   AFTER delete
AS 
BEGIN
    --红字收款单扩展自定义项26,可以联查到源收款单
    if exists(select b.chdefine26 from Ap_CloseBill a inner join deleted b on a.iID = b.iID where a.cVouchType = '49' and  exists (select 1 from Ap_CloseBill c where c.cVouchID = b.chdefine26 and  c.cVouchType = '48'))
    begin
        --红字收款单扩展自定义项25,无法联查到蓝字收款单
        if exists(select  b.chdefine25 from Ap_CloseBill a inner join deleted b on a.iID = b.iID where a.cVouchType = '49' and not  exists (select 1 from Ap_CloseBill c where c.cVouchID = b.chdefine25 and  c.cVouchType = '48'))
        begin
            --回写来源收款单,累计转定金金额(表头自定义项16),可转定金余额(表头自定义项7)
            update Ap_CloseBill set cDefine16 =ISNULL(cdefine16,0)-b.iAmount, cDefine7 =ISNULL(cdefine7,0)+b.iAmount from Ap_CloseBill a 
            inner join ( select iAmount ,b.chdefine26 from Ap_CloseBill a inner join deleted b on a.iID = b.iID where cVouchType = '49') b on a.cVouchID = b.chdefine26 
            and    a.cVouchType='48'
        end
        else
        begin
            DECLARE @cvoucherid NVARCHAR(120)
            select @cvoucherid = b.chdefine25 from Ap_CloseBill a inner join deleted b on a.iID = b.iID where a.cVouchType = '49' and  exists (select 1 from Ap_CloseBill c where c.cVouchID = b.chdefine25 and  c.cVouchType = '48')
            DECLARE @msg NVARCHAR(50)
            SET @msg='请先删除蓝字收款单'+@cvoucherid
            RAISERROR(@msg,16,1)
            ROLLBACK 
        end
    end
End
go

 

标签:触发器,iID,cVouchType,CloseBill,Ap,select,where,模板
From: https://www.cnblogs.com/birdGe/p/17275836.html

相关文章

  • 微信小程序使用 wxs 对模板数据格式化展示
    在小程序页面展示时,对时间、金额进行格式化处理。但是每次在js文件中处理,并setData感觉无比麻烦。是否可以直接在wxml模板文件中进行处理。正好发现了微信小程序wxs,完全满足需求。微信小程序wxs使用场景WXS(WeiXinScript)是微信创造的一套脚本语言,虽然看起来很JS异常......
  • 【模板】逆单源最短(反向建图) + spfa
    题目要求:不仅要求单源最短路径,还要求其余点到该点的最短路径做法:建立反图求逆单源最短路径,至于单源最短路径选择合适于题目即可参考题目1#include<iostream>2#include<queue>3#include<cstring>45usingnamespacestd;67typedeflonglongLL;8typ......
  • 工作日报-模板
    工作日报汇报:输入“@+人名”提及汇报人抄送:输入“@+人名”提及抄送人XX月XX日今日进展在这描述每天重点工作的背景和进展;如有相关材料,可以输入“@+文档名”引......
  • 工作周报-模板
    工作周报【周报模板说明】一、周报内容:1、第一项「待决策事项」,列明需要上级参与并提供决策支持的事项;2、第二项「本周重点工作」,汇报本周自己或所负责部门的重点工作,......
  • LabVIEW Excel工具包快速读写EXCEL样式模板生成测试报告制作
    LabVIEWExcel工具包快速读写EXCEL样式模板生成测试报告制作YID:86199673187774245......
  • 001-Idea用法-在pom.xml文件中增加模板注释
    XML文件注释快捷键为:Ctrl+Shift+/  今天发现,在pom.xml文件中写注释,输入<!,没有任何提示,想写个完整的注释,还需要<!-- -->把这一串完整的写进去,然后中间空两格,再写中间......
  • idea注释模板 pom.xml 配置(经典)
    方法注释生成:Setting->Editor->LiveTemplates,自定义:TemplateGroup,再定义:MethodTemplate。**@ClassName$name$*@DescriptionTODO*@Param$params$*......
  • Java 生成各种 PDF 实战方案(图片、模板、表格)
    刚接到了一个需求,生成一个pdf,一开始以为挺简单的,通过模板生成嘛,我也发过相应的文章,根据模板直接生成pdf,响应到前端或者根据模板生成pdf,直接指定下载位置,这两种方案都可以,......
  • FastAPI开发运维模板
    main.pyfromtypingimportUnionfromfastapiimportFastAPIfrompydanticimportBaseModelfromtypingimportOptionalimportosapp=FastAPI()classK8s......
  • 企业降本增效法宝之小程序营销模板
    近年来,小程序作为一种全新的应用形态,受到了人们的广泛关注。由于其轻量级、易传播、低成本等特点,博得了越来越多的企业和开发者的青睐。其中,小程序营销模版 作为小程序应......