香港云主机最佳企业级服务商!

ADSL拨号VPS包含了中国大陆(联通,移动,电信,)

中国香港,国外拨号VPS。

当前位置:云主机 > MSSQL >

电信ADSL拨号VPS
联通ADSL拨号VPS
移动ADSL拨号VPS

Sql Server使用cursor处理重复数据过程详解


时间:2020-10-31 14:27 作者:admin


/************************************************************  * 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; --关闭游标     DEALLOCATE email; --释放游标   END END

(责任编辑:admin)






帮助中心
会员注册
找回密码
新闻中心
快捷通道
域名登录面板
虚机登录面板
云主机登录面板
关于我们
关于我们
联系我们
联系方式

售前咨询:17830004266(重庆移动)

企业QQ:383546523

《中华人民共和国工业和信息化部》 编号:ICP备00012341号

Copyright © 2002 -2018 香港云主机 版权所有
声明:香港云主机品牌标志、品牌吉祥物均已注册商标,版权所有,窃用必究

云官方微信

在线客服

  • 企业QQ: 点击这里给我发消息
  • 技术支持:383546523

  • 公司总台电话:17830004266(重庆移动)
  • 售前咨询热线:17830004266(重庆移动)