SQLServer中用存储过程去除表中重复客户信息

本文介绍了一个在SQLServer中删除表中重复客户信息的存储过程。该存储过程通过游标遍历所有重复的客户ID,保留其中一个记录,删除其余重复项,从而实现数据的去重。
摘要由CSDN通过智能技术生成

 以下是本人在建立多维数据集时对重复客户信息处理所采用的存储过程:

create procedure Sp_DeleteDuplicateCustomerInfo
as
 declare @CustomerId bigint
 declare @Count int
 declare @TopCount int
 declare @StrCustomerId char(7)
 declare @StrTopCount char(1)
 
 declare deleteCur cursor for
 select CustomerId,count(customerID) counts from T_CustomerInfo group by customerID
having count(customerID)>1
 open deleteCur
 fetch next from deleteCur into @CustomerId,@Count
 while @@fetch_status=0
 begin
  set @TopCount=@Count-1
  set @StrCustomerId = cast(@CustomerId as char(7))
  set @StrTopCount = cast(@TopCount as char(1))
  print 'delete from T_CustomerInfo where recId in
  (select top '+cast(

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值