码迷,mamicode.com
首页 > 数据库 > 详细

sqlserver存取过程-游标

时间:2016-06-19 22:45:55      阅读:233      评论:0      收藏:0      [点我收藏+]

标签:

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;

sqlserver存取过程-游标

标签:

原文地址:http://www.cnblogs.com/meisp/p/5598904.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!