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
  • 相关阅读:
    Linux 设置主机名和 IP 地址的映射关系
    Zookeeper 数据查看工具 ZooInspector 的使用
    Zookeeper 集群
    Zookeeper 监控指定节点数据变化
    Zookeeper 常用命令
    Spring整合ActiveMQ持久化到Mysql数据库
    Activemq5.15.5持久化到mysql8.0.20
    ActiveMQ支持的协议
    SIGINT SIGTERM SIGKILL区别
    lograte -日志轮询log
  • 原文地址:https://www.cnblogs.com/zxjyuan/p/2533456.html
Copyright © 2011-2022 走看看