亚洲免费在线-亚洲免费在线播放-亚洲免费在线观看-亚洲免费在线观看视频-亚洲免费在线看-亚洲免费在线视频

存儲過程,游標和觸發器實例

系統 1930 0
原文: 存儲過程,游標和觸發器實例[原創]

  自己寫的存儲過程與游標結合使用的實例,與大家分享,也供自己查閱,僅供參考:

      
        --
      
      
        使用游標循環處理,刪除重復的記錄
      
      
        declare
      
      
        @UserID
      
      
        int
      
      
        declare
      
      
        @UserName
      
      
        varchar
      
      (
      
        32
      
      
        )

    
      
      
        declare
      
      
        @RealName
      
      
        varchar
      
      (
      
        32
      
      
        )

    
      
      
        declare
      
      
        @UnitFlag
      
      
        int
      
      
        declare
      
      
        @Email2
      
      
        varchar
      
      (
      
        64
      
      
        )

    
      
      
        declare
      
      
        @Mobile
      
      
        varchar
      
      (
      
        64
      
      
        )

    
      
      
        declare
      
      
        @Start
      
      
        int
      
      
        declare
      
      
        @End
      
      
        int
      
      
        declare
      
      
        @Type
      
      
        varchar
      
      (
      
        16
      
      
        )

    
      
      
        declare
      
      
        @IsSubscribe
      
      
        bit
      
      
        declare
      
       curEmailTotalLib 
      
        cursor
      
      
        for
      
       (
      
        select
      
       UserID,UserName,RealName,UnitFlag,Email,Mobile,IsSubscribe 
      
        from
      
      
         Task_IntermediateData)

    
      
      
        open
      
       curEmailTotalLib                
      
        --
      
      
        打開游標
      
      
        fetch
      
      
        next
      
      
        from
      
       curEmailTotalLib 
      
        into
      
      
        @UserID
      
      , 
      
        @UserName
      
      , 
      
        @RealName
      
      , 
      
        @UnitFlag
      
      , 
      
        @Email2
      
      , 
      
        @Mobile
      
      , 
      
        @IsSubscribe
      
      
        while
      
      
        @@fetch_status
      
      
        =
      
      
        0
      
      
        --
      
      
        獲取成功
      
      
        begin
      
      
        --
      
      
        在郵件系統總庫中不存在此用戶ID,不存在此郵箱,并且用戶訂閱過
      
      
        if
      
      
        not
      
      
        exists
      
      (
      
        select
      
      
        *
      
      
        from
      
       Task_EmailTotalLib 
      
        where
      
       UserID 
      
        =
      
      
        @UserID
      
      
        )

            
      
      
        and
      
      
        not
      
      
        exists
      
      (
      
        select
      
      
        *
      
      
        from
      
       Task_EmailTotalLib 
      
        where
      
       Email 
      
        =
      
      
        @Email2
      
      
        )

            
      
      
        and
      
      
        @IsSubscribe
      
      
        =
      
      
        1
      
      
        begin
      
      
        set
      
      
        @Start
      
      
        =
      
      
        charindex
      
      (
      
        '
      
      
        @
      
      
        '
      
      , 
      
        @Email2
      
      , 
      
        0
      
      
        )

            
      
      
        set
      
      
        @End
      
      
        =
      
      
        charindex
      
      (
      
        '
      
      
        .
      
      
        '
      
      , 
      
        @Email2
      
      , 
      
        @Start
      
      
        )

            
      
      
        if
      
      
        @Start
      
      
        !=
      
      
        0
      
      
        and
      
      
        @End
      
      
        !=
      
      
        0
      
      
        begin
      
      
        --
      
      
        不是垃圾郵件
      
      
        if
      
      
        @Email2
      
      
        is
      
      
        not
      
      
        null
      
      
        and
      
      
        ltrim
      
      (
      
        rtrim
      
      (
      
        @Email2
      
      )) 
      
        <>
      
      
        ''
      
      
        begin
      
      
        if
      
      
        not
      
      
        exists
      
      (
      
        select
      
      
        *
      
      
        from
      
       Task_JunkEmail 
      
        where
      
       Email 
      
        =
      
      
        @Email2
      
      
        )

                        
      
      
        begin
      
      
        begin
      
      
         try

                                
      
      
        set
      
      
        @Type
      
      
        =
      
      
        substring
      
      (
      
        @Email2
      
      , 
      
        @Start
      
      
        +
      
      
        1
      
      , 
      
        @End
      
      
        -
      
      
        @Start
      
      
        -
      
      
        1
      
      
        )

                                
      
      
        if
      
      
        @Type
      
      
        !=
      
      
        '
      
      
        qq
      
      
        '
      
      
        and
      
      
        @Type
      
      
        !=
      
      
        '
      
      
        126
      
      
        '
      
      
        and
      
      
        @Type
      
      
        !=
      
      
        '
      
      
        163
      
      
        '
      
      
        and
      
      
        @Type
      
      
        !=
      
      
        '
      
      
        sina
      
      
        '
      
      
        and
      
      
        @Type
      
      
        !=
      
      
        '
      
      
        sohu
      
      
        '
      
      
        and
      
      
        @Type
      
      
        !=
      
      
        '
      
      
        gmail
      
      
        '
      
      
        and
      
      
        @Type
      
      
        !=
      
      
        '
      
      
        hotmail
      
      
        '
      
      
        and
      
      
        @Type
      
      
        !=
      
      
        '
      
      
        yahoo
      
      
        '
      
      
        and
      
      
        @Type
      
      
        !=
      
      
        '
      
      
        139
      
      
        '
      
      
        and
      
      
        @Type
      
      
        !=
      
      
        '
      
      
        263
      
      
        '
      
      
        and
      
      
        @Type
      
      
        !=
      
      
        '
      
      
        yeah
      
      
        '
      
      
        and
      
      
        @Type
      
      
        !=
      
      
        '
      
      
        cnki
      
      
        '
      
      
        begin
      
      
        set
      
      
        @Type
      
      
        =
      
      
        '
      
      
        extra
      
      
        '
      
      
        end
      
      
        insert
      
      
        into
      
      
         Task_EmailTotalLib(UserID, UserName, RealName, Email, Mobile,

                                Priority, MailType, LibType, FpIsSend, CpIsSend, UpIsSend, VpIsSend, WpIsSend,

                                XpIsSend, YpIsSend, ZpIsSend, SendCount, SucCount, FailCount, CreditRate, IsJunkEmail,

                                IsSubscribe, IsUsed, Memo) 
      
      
        values
      
      (
      
        @UserID
      
      , 
      
        @UserName
      
      , 
      
        @RealName
      
      , 
      
        @Email2
      
      , 
      
        @Mobile
      
      
        ,

                                
      
      
        2
      
      , 
      
        @Type
      
      , 
      
        @UnitFlag
      
      , 
      
        0
      
      , 
      
        0
      
      , 
      
        0
      
      , 
      
        0
      
      , 
      
        0
      
      , 
      
        0
      
      , 
      
        0
      
      , 
      
        0
      
      , 
      
        0
      
      , 
      
        0
      
      , 
      
        0
      
      , 
      
        10
      
      , 
      
        0
      
      , 
      
        @IsSubscribe
      
      , 
      
        0
      
      , 
      
        ''
      
      
        )

                            
      
      
        end
      
      
         try

                            
      
      
        begin
      
      
         catch

                                
      
      
        print
      
      
        '
      
      
        @Email2:
      
      
        '
      
      
        +
      
      
        @Email2
      
      
        +
      
      
        '
      
      
        charindex(
      
      
        ''
      
      
        @
      
      
        ''
      
      
        , @Email2, 0)
      
      
        '
      
      
        +
      
      
        charindex
      
      (
      
        '
      
      
        @
      
      
        '
      
      , 
      
        @Email2
      
      , 
      
        0
      
      )
      
        +
      
      
        '
      
      
          @Start
      
      
        '
      
      
        +
      
      
        @Start
      
      
        +
      
      
        '
      
      
          @End
      
      
        '
      
      
        +
      
      
        @End
      
      
        +
      
      
        '
      
      
          @End - @Start - 1:
      
      
        '
      
      
        +
      
      
        @End
      
      
        -
      
      
        @Start
      
      
        -
      
      
        1
      
      
        end
      
      
         catch

                        
      
      
        end
      
      
        end
      
      
        end
      
      
        end
      
      
        fetch
      
      
        next
      
      
        from
      
       curEmailTotalLib 
      
        into
      
      
        @UserID
      
      , 
      
        @UserName
      
      , 
      
        @RealName
      
      , 
      
        @UnitFlag
      
      , 
      
        @Email2
      
      , 
      
        @Mobile
      
      , 
      
        @IsSubscribe
      
      
        end
      
      
        close
      
       curEmailTotalLib            
      
        --
      
      
        關閉游標
      
      
        deallocate
      
       curEmailTotalLib        
      
        --
      
      
        釋放游標
      
    

  觸發器實例:插入數據時,觸發器獲取這條數據ID,自動修改,比程序處理更方便。

  Create trigger tg_url_update? on [dbo].UrlTotal for insert as
    declare @getid int;?
    declare @url varchar(128);
    set @getid=(select id from inserted);
    set @url='Test.aspx?id='+cast(@getid as varchar(50))?
    update UrlTotal set url=@url where id=@getid

?????? 謝謝閱讀~~

存儲過程,游標和觸發器實例


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 久久久91精品国产一区二区三区 | 国产老年人性视频 | 国产精品自在自线免费观看 | 成人a毛片免费全部播放 | 日韩精品国产自在久久现线拍 | 国产成人精品实拍在线 | 99久久免费国产精品 | 精品亚洲性xxx久久久 | 亚洲精品国产一区二区三区在 | 成人特黄午夜性a一级毛片 成人特级毛片69免费观看 | 天天狠狠弄夜夜狠狠躁·太爽了 | 亚洲www视频| 国产成人综合洲欧美在线 | 欧美日韩成人午夜免费 | 亚洲人成影院午夜网站 | 亚欧在线视频 | 在线亚洲欧美性天天影院 | 香蕉视频在线观看国产 | 最新亚洲国产有精品 | 婷婷免费高清视频在线观看 | 国产日韩欧美中文 | 国产91在线看 | 一本一道波多野结衣一区二区 | 日韩精品综合 | 色综合久久久久久中文网 | 九九影视理伦片 | 国产美女mm131爽爽爽免费 | 亚洲精品一区二区不卡 | 热久久这里是精品6免费观看 | 国产欧美成人xxx视频 | 免费看一区二区三区 | 午夜国产福利视频 | 99热手机在线观看 | 久久91精品久久91综合 | 成人国产三级精品 | 国产精品亚洲片在线牛牛影视 | 国产精品免费看 | 久久美女免费视频 | 国产区精品一区二区不卡中文 | 97精品国产91久久久久久 | 91福利刘玥国产在线观看 |