执行如下存储过程:
declare @scp_code varchar(50);
declare @id INT;
DECLARE cur CURSOR FOR -- 查找 s_link 有反复的门路
select cp_code from cp_sick
GROUP BY cp_code, s_link HAVING count(s_link) > 1;
OPEN cur
fetch next from cur into @scp_code
while(@@fetch_status=0)
begin
print(@scp_code)
set @id=0
update cp_sick SET s_link=@id,@id=@id+1 WHERE cp_code = @scp_code;
fetch next from cur into @scp_code
end
close cur
DEALLOCATE cur