?以下是本人在建立多维数据集时对重复客户信息处理所采用的存储过程:
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(@TopCount as char(1))+' recId from T_CustomerInfo where CustomerId='+cast(@CustomerId as char(7))
??exec('delete from T_CustomerInfo where recId in ??(select top '+@StrTopCount+' recId from T_CustomerInfo where CustomerId='+@StrCustomerId+')')
??fetch next from deleteCur into @CustomerId,@Count ?end ?close deleteCur ?deallocate deleteCur
go
(编辑:李大同)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|