首页 > 数据库技术 > 详细

sqlserver存取过程-游标

时间:2016-06-19 22:45:46      阅读:222      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!