ALTER proc [dbo].[common_proc_temp2]

as  begin

declare @id varchar(50);
declare @cbcontractid varchar(50);
declare @xh int ;
declare owner_03_cursor cursor scroll
for select id from cb_contract where canton_id like '20%'
--2.打开游标
open owner_03_cursor
fetch next from owner_03_cursor into @cbcontractid --into的变量数量必须与游标查询结果集的列数相同
while @@fetch_status=0 --提取成功,进行下一条数据的提取操作
begin
set @xh=1
declare owner_04_cursor cursor scroll
for select id from cb_contract_change where f_cbcontractid=@cbcontractid order by bgrq asc
open owner_04_cursor
fetch next from owner_04_cursor into @id
while @@fetch_status=0
begin
update cb_contract_change set xh=@xh where id=@id
set @xh=@xh+1;
fetch next from owner_04_cursor into @id
end
close owner_04_cursor;
deallocate owner_04_cursor;

fetch next from owner_03_cursor into @cbcontractid --移动游标
end
close owner_03_cursor;
deallocate owner_03_cursor;
end;