zoukankan      html  css  js  c++  java
  • Replay_InsertTrigger

    set ANSI_NULLS ON
    set QUOTED_IDENTIFIER ON
    go


    ALTER TRIGGER [Replay_InsertTrigger] 
        ON [dbo].[Sms_SendHistoryReplay] 
        INSTEAD OF INSERT 
    AS 
    BEGIN 
        DECLARE @LastReplayID INT
        DECLARE @LastPhoneNum NVARCHAR(20)
        DECLARE @FullContents NVARCHAR(200)

        DECLARE @ReplayID INT
        DECLARE @HistoryID INT
        DECLARE @UserID INT
        DECLARE @UserName NVARCHAR(50)
        DECLARE @PhoneNum NVARCHAR(20)
        DECLARE @Contents NVARCHAR(200)
        DECLARE @SpNumber NVARCHAR(50)
        DECLARE @CreateTime DATETIME
        DECLARE @IsLong INT

        SELECT @ReplayID=ReplayID,@HistoryID=HistoryID,@UserID=UserID,@UserName=UserName,
        @PhoneNum=PhoneNum,@Contents=Contents,@SpNumber=SpNumber,@CreateTime=CreateTime,@IsLong=IsLong
        FROM inserted
        
        --前面包含3个问号“???”判断为长短信
        IF(substring(@Contents,1,3)='???')
        BEGIN
            SET @Contents = substring(@Contents,4,len(@Contents))
            SELECT TOP 1 @LastReplayID=ReplayID,@LastPhoneNum=PhoneNum FROM Sms_SendHistoryReplay ORDER BY ReplayID DESC
            
            --与最新的一条号码相同,则组合在上一条短信中
            --如果号码不相同,则重新插入。
            IF(@LastPhoneNum=@PhoneNum)
            BEGIN    
                IF(substring(@Contents,1,2)='信息' or substring(@Contents,1,2)='笔记')
                BEGIN
                    UPDATE Sms_SendHistoryReplay SET Contents=@Contents+Contents WHERE ReplayID=@LastReplayID
                END
                ELSE
                BEGIN
                    UPDATE Sms_SendHistoryReplay SET Contents=Contents+@Contents WHERE ReplayID=@LastReplayID
                END
            END
            ELSE
            BEGIN        
                INSERT INTO Sms_SendHistoryReplay(ReplayID,HistoryID,UserID,UserName,PhoneNum,Contents,SpNumber,CreateTime,PushStatus)
                VALUES(@ReplayID,@HistoryID,@UserID,@UserName,@PhoneNum,@Contents,@SpNumber,GETDATE(),2)
            END
        END
        ELSE
        BEGIN
            INSERT INTO Sms_SendHistoryReplay(ReplayID,HistoryID,UserID,UserName,PhoneNum,Contents,SpNumber,CreateTime,PushStatus)
            VALUES(@ReplayID,@HistoryID,@UserID,@UserName,@PhoneNum,@Contents,@SpNumber,GETDATE(),0)
        END
        
    END
  • 相关阅读:
    vs2010 怎样设置文本编辑窗口和解决方案资源管理器同步?
    google浏览器如何导出书签
    C#面试题
    Inkscape tricks
    jupyter-notebook kernel died
    matplotlib 显示中文
    Ubuntu+apt-get update时的源
    vscode设置出错, 无法自动补全
    Ubuntu+vscode打不开
    Ubuntu+Firefox总是打不开网页
  • 原文地址:https://www.cnblogs.com/zxjyuan/p/2533456.html
Copyright © 2011-2022 走看看