• 一个有用的触发器



    这个触发器主要是值更改前后的获取,以及字符串分隔

    CREATE TRIGGER historyaddress  ON dbo.gdzclist
    FOR UPDATE
    AS
    if UPDATE(chrnowaddress)
    begin
    declare @chrnowaddress varchar(255),@intID integer,@chrhistoryaddress varchar(500),@regtime datetime,@i integer,@tmptime varchar(500)
    select @tmptime=chrnowaddress from inserted
    select @chrnowaddress=chrnowaddress, @intID=ID,@chrhistoryaddress=chrhistoryaddress,@regtime=dtmregtime from deleted
    if (@chrnowaddress='' )
       return
    if (@chrnowaddress=@tmptime)
       return
     if ( rtrim(@chrhistoryaddress+'')=''  or  @chrhistoryaddress is null)
     begin
       select @chrnowaddress=@chrnowaddress+'['+convert(char(4),year(@regtime))+'-'+convert(varchar(2),month(@regtime))+'-'+convert(varchar(2),day(@regtime))+'--'+convert(char(4),year(getdate()))+'-'+convert(varchar(2),month(getdate()))+'-'+convert(varchar(2),day(getdate()))+']'
      end
           else
     begin
        select @i=PATINDEX('%--%', @chrhistoryaddress)
        select @tmptime=substring(@chrhistoryaddress,@i+2,len(@chrhistoryaddress)-@i-2)
          
         WHILE (PATINDEX('%--%', @tmptime)<>0)
      BEGIN
      select @i=PATINDEX('%--%', @tmptime)
      select @tmptime=substring(@tmptime,@i+2,len(@tmptime)-@i-1)
      END
       select @chrnowaddress=@chrhistoryaddress+';'+@chrnowaddress+'['+convert(char(4),year(@tmptime))+'-'+convert(varchar(2),month(@tmptime))+'-'+convert(varchar(2),day(@tmptime))+'--'+convert(char(4),year(getdate()))+'-'+convert(varchar(2),month(getdate()))+'-'+convert(varchar(2),day(getdate()))+']'
     end
    update gdzclist set chrhistoryaddress=@chrnowaddress where id=@intID
    end

  • 相关阅读:
    谈谈django里的Contex和RequestContext---向模板里添加全局变量
    Django如何重设Admin密码
    javascript的闭包
    javascript的this用法
    阮一峰---javascript系列
    Javascript继承机制总结 [转]
    chrome浏览器开发者工具使用教程[转]
    WAMP设置默认访问目录
    js 去掉空格.回车.换行
    网站服务器上载目录
  • 原文地址:https://www.cnblogs.com/isMe/p/270583.html
Copyright © 2020-2023  润新知