主頁(yè) > 知識(shí)庫(kù) > Sql Server使用cursor處理重復(fù)數(shù)據(jù)過(guò)程詳解

Sql Server使用cursor處理重復(fù)數(shù)據(jù)過(guò)程詳解

熱門標(biāo)簽:洛陽(yáng)外呼系統(tǒng)平臺(tái) 怎樣把地圖標(biāo)注導(dǎo)入公司地址 地圖標(biāo)注一個(gè)圓圈怎么用 真人語(yǔ)音電銷機(jī)器人 如何在地圖標(biāo)注自己店鋪 寧波人工外呼系統(tǒng)有效果嗎 電銷機(jī)器人被曝光 廣州人工電銷機(jī)器人費(fèi)用 400外呼系統(tǒng)合法
/************************************************************ 
 * Code formatted by setyg 
 * Time: 2014/7/29 10:04:44 
 ************************************************************/ 
 
CREATE PROC HandleEmailRepeat 
AS  
DECLARE email CURSOR  
FOR 
  SELECT e.email 
     ,e.OrderNo 
     ,e.TrackingNo 
  FROM  Email20140725 AS e 
  WHERE e.[status] = 0 
  ORDER BY 
      e.email 
     ,e.OrderNo 
     ,e.TrackingNo 
 
BEGIN 
  DECLARE @@email       VARCHAR(200) 
      ,@firstEmail     VARCHAR(200) 
      ,@FirstOrderNO    VARCHAR(300) 
      ,@FirstTrackingNO   VARCHAR(300) 
      ,@NextEmail      VARCHAR(200) 
      ,@@orderNO      VARCHAR(300) 
      ,@NextOrderNO     VARCHAR(50) 
      ,@@trackingNO     VARCHAR(300) 
      ,@NextTrackingNO   VARCHAR(50) 
   
  BEGIN 
    OPEN email; 
    FETCH NEXT FROM email INTO @firstEmail,@FirstOrderNO, @FirstTrackingNO; 
    FETCH NEXT FROM email INTO @NextEmail,@NextOrderNO, @NextTrackingNO; 
    IF @NextEmail!=@firstEmail 
    BEGIN 
      INSERT INTO Email20140725Test 
       ( 
        email 
        ,OrderNo 
        ,TrackingNo 
       ) 
      VALUES 
       ( 
        @firstEmail 
        ,@FirstOrderNO 
        ,@FirstTrackingNO 
       );  
      SET @@email = @NextEmail; 
      SET @@orderNO = @NextOrderNO; 
      SET @@trackingNO = @NextTrackingNO; 
    END 
    ELSE 
    BEGIN 
      SET @@email = @NextEmail; 
      SET @@orderNO = @FirstOrderNO+'、'+@NextOrderNO; 
      SET @@trackingNO = @FirstTrackingNO+'、'+@NextTrackingNO; 
    END 
     
     
     
    FETCH NEXT FROM email INTO @NextEmail,@NextOrderNO,@NextTrackingNO 
    WHILE @@fetch_status=0 
    BEGIN 
      IF @NextEmail=@@email 
      BEGIN 
        IF (@NextOrderNO!=@@orderNO) 
          SET @@orderNO = @@orderNO+'、'+@NextOrderNO 
         
        PRINT 'orderNO:'+@@orderNO  
         
        IF (@@trackingNO!=@NextTrackingNO) 
          SET @@trackingNO = @@trackingNO+'、'+@NextTrackingNO 
         
        PRINT 'trackingNO:'+@@trackingNO 
      END 
      ELSE 
      BEGIN 
        INSERT INTO Email20140725Test 
         ( 
          email 
          ,OrderNo 
          ,TrackingNo 
         ) 
        VALUES 
         ( 
          @@email 
          ,@@orderNO 
          ,@@trackingNO 
         ); 
        SET @@email = @NextEmail; 
        SET @@orderNO = @NextOrderNO; 
        SET @@trackingNO = @NextTrackingNO; 
      END 
      FETCH NEXT FROM email INTO @NextEmail,@NextOrderNO, @NextTrackingNO; 
    END 
    CLOSE email; --關(guān)閉游標(biāo) 
    DEALLOCATE email; --釋放游標(biāo) 
  END 
END

您可能感興趣的文章:
  • SQL Server數(shù)據(jù)庫(kù)刪除數(shù)據(jù)集中重復(fù)數(shù)據(jù)實(shí)例講解
  • sqlserver清除完全重復(fù)的數(shù)據(jù)只保留重復(fù)數(shù)據(jù)中的第一條
  • SQL Server中刪除重復(fù)數(shù)據(jù)的幾個(gè)方法
  • sqlserver中重復(fù)數(shù)據(jù)值只取一條的sql語(yǔ)句
  • sqlserver合并DataTable并排除重復(fù)數(shù)據(jù)的通用方法分享
  • 教你幾種在SQLServer中刪除重復(fù)數(shù)據(jù)方法
  • MSSql簡(jiǎn)單查詢出數(shù)據(jù)表中所有重復(fù)數(shù)據(jù)的方法

標(biāo)簽:北海 石家莊 煙臺(tái) 東營(yíng) 珠海 晉中 南昌 咸寧

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《Sql Server使用cursor處理重復(fù)數(shù)據(jù)過(guò)程詳解》,本文關(guān)鍵詞  Sql,Server,使用,cursor,處理,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問(wèn)題,煩請(qǐng)?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無(wú)關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《Sql Server使用cursor處理重復(fù)數(shù)據(jù)過(guò)程詳解》相關(guān)的同類信息!
  • 本頁(yè)收集關(guān)于Sql Server使用cursor處理重復(fù)數(shù)據(jù)過(guò)程詳解的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章