ITPub博客

首页 > Linux操作系统 > Linux操作系统 > 在Sql Sever 中删除两个列以上的重复记录

在Sql Sever 中删除两个列以上的重复记录

原创 Linux操作系统 作者:zhaoyu728 时间:2019-01-08 19:06:06 0 删除 编辑

create procedure scmx_delbom as
declare @same varchar(110),@id integer--声明变量,存储fetch提取的数据

declare scmx_cursor cursor for
select ltrim(rtrim(mycg))+ltrim(rtrim(dlhk)),count(*) from bom group by dlhk,mycg having count(*)>1
open scmx_cursor

-- 执行第一个fetch并存储局部变量的值
-- 局部变量值的顺序必须和select语句中的顺序一致
fetch scmx_cursor into @same,@id
-- 检查游标的状态,找出所有可执行的行
while @@fetch_status=0
begin
set @id=@id-1
set rowcount @id
delete from bom where ltrim(rtrim(mycg))+ltrim(rtrim(dlhk))=@same
FETCH scmx_cursor into @same,@id
end
close scmx_cursor
deallocate scmx_cursor

sp_help scmx_delbom


来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/8382469/viewspace-259851/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2006-12-03

  • 博文量
    36
  • 访问量
    32590