代码
--删除重复数据,只保留记录号最大的
declare mycursor cursor
for
select addinip from testdb group by addinip having count(addinip)>1
open mycursor
declare @ip sysname
fetch next from mycursor into @ip
while(@@fetch_status=0)
begin
print @ip
declare @aid int
select @aid=max(autoid) from testdb where addinip=@ip
print @aid
-- 删除重复数据,只保留记录号最大的那条记录
delete from testdb where autoid <> @aid and addinip=@ip
fetch next from mycursor into @ip
end
close mycursor
deallocate mycursor
declare mycursor cursor
for
select addinip from testdb group by addinip having count(addinip)>1
open mycursor
declare @ip sysname
fetch next from mycursor into @ip
while(@@fetch_status=0)
begin
print @ip
declare @aid int
select @aid=max(autoid) from testdb where addinip=@ip
print @aid
-- 删除重复数据,只保留记录号最大的那条记录
delete from testdb where autoid <> @aid and addinip=@ip
fetch next from mycursor into @ip
end
close mycursor
deallocate mycursor