关于sql:sql-server-根据行号更新某列的数据可以根据其他列做筛选

34次阅读

共计 353 个字符,预计需要花费 1 分钟才能阅读完成。

执行如下存储过程:

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

正文完
 0