zoukankan      html  css  js  c++  java
  • 触发器

    USE [UFDATA_010_2013]
    GO
    /****** Object:  Trigger [dbo].[prodb_trigger]    Script Date: 03/12/2016 08:47:34 ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER trigger [dbo].[prodb_trigger] on [dbo].[PRO_Db_b]
    for insert,update,delete
    as
    begin
        declare @inserted int,
                @deleted int,
                @startdate datetime,
                @enddate datetime,
                @depcode nvarchar(50),
                @distributecotton nvarchar(512),
                @dbqty float,
                @dbqtyback float
        select @inserted=COUNT(*) from inserted
        select @deleted=COUNT(*) from deleted
       
        if @inserted>0 and @deleted=0
        begin
            --insert
            select @startdate=startdate,@enddate=enddate,@depcode=depcode,@dbqty=dbqty,@distributecotton=distributecotton from  inserted;
            update a set a.qtysum=a.qtysum+@dbqty from PRO_Element_b a,PRO_Element b where b.id=a.element_id and b.elementdate>=@startdate and b.elementdate<=@enddate and b.depcode=@depcode and a.distributecotton=@distributecotton
        end
        else if @inserted>0 and @deleted>0
        begin
            --update
            select @startdate=startdate,@enddate=enddate,@depcode=depcode,@dbqty=dbqty,@distributecotton=distributecotton from  inserted;
            select @dbqtyback=dbqty from  deleted;
            update a set a.qtysum=a.qtysum+@dbqty-@dbqtyback from PRO_Element_b a,PRO_Element b where b.id=a.element_id and b.elementdate>=@startdate and b.elementdate<=@enddate and b.depcode=@depcode and a.distributecotton=@distributecotton
        end
        else if @inserted=0 and @deleted>0
        begin  
            --delete
            select @startdate=startdate,@enddate=enddate,@depcode=depcode,@dbqty=dbqty,@distributecotton=distributecotton from  deleted;
            update a set a.qtysum=a.qtysum-@dbqty from PRO_Element_b a,PRO_Element b where b.id=a.element_id and b.elementdate>=@startdate and b.elementdate<=@enddate and b.depcode=@depcode and a.distributecotton=@distributecotton
        end
    end

  • 相关阅读:
    linux的vim按了ctrl+s之后假死的解决办法
    linux下的终端模拟器urxvt的配置
    vim下正则表达式的非贪婪匹配
    linux中的一个看图的软件
    解决windows的控制台显示utf8乱码的问题
    [PHP][位转换积累]之异或运算的简单加密应用
    [PHP][REDIS]phpredis 'RedisException' with message 'read error on connection'
    [PHP][位转换积累]之与运算截取二进制流的值
    [PHP][位转换积累]之pack和unpack
    [正则表达式]PCRE反向分组引用
  • 原文地址:https://www.cnblogs.com/passerlee/p/5267916.html
Copyright © 2011-2022 走看看