/************************************************************ * 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
免责声明:
1、本网站所有发布的源码、软件和资料均为收集各大资源网站整理而来;仅限用于学习和研究目的,您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容。
不得使用于非法商业用途,不得违反国家法律。否则后果自负!
2、本站信息来自网络,版权争议与本站无关。一切关于该资源商业行为与www.niceym.com无关。
如果您喜欢该程序,请支持正版源码、软件,购买注册,得到更好的正版服务。
如有侵犯你版权的,请邮件与我们联系处理(邮箱:skknet@qq.com),本站将立即改正。
NICE源码网 MsSql Sql Server使用cursor处理重复数据过程详解 https://www.niceym.com/55194.html
猜你喜欢
- sqlserver存储过程语法详解 2022-05-24
- SQL Server 2005降级到2000的正确操作步骤分享 2022-05-24
- SQL Server 2005 数据库转 SQL Server 2000的方法小结 2022-05-24
- Sql中将datetime转换成字符串的方法(CONVERT) 2022-05-24
- mssql和sqlite中关于if not exists 的写法 2022-05-24
- 在SQL Server中查询资料库的TABLE数量与名称的sql语句 2022-05-24
- 通过系统数据库获取用户所有数据库中的视图、表、存储过程 2022-05-24
- 使用phpMyAdmin修改MySQL数据库root用户密码的方法 2022-05-24
- 一段脚本实现自动备份并保存最近几天的SQL数据库 2022-05-24
- sql查询表中根据某列排序的任意行语句 2022-05-24