SQL cursor用法实例
程序员文章站
2024-02-10 14:30:40
复制代码 代码如下:declare @oldid varchar(50) declare @customerid varchar(50) ...
复制代码 代码如下:
declare @oldid varchar(50)
declare @customerid varchar(50)
declare my_cursor cursor --定义游标
for (select customerid,oldid from customer where area='bj') --查出需要的集合放到游标中
open my_cursor; --打开游标
fetch next from my_cursor into @customerid,@oldid; --读取第一行数据
while @@fetch_status = 0
begin
declare @otherpro varchar(500)
declare @statusid varchar(200)
declare @userid varchar(200)
declare @finaluserid varchar(200)
select @otherpro=otherpro,@statusid=customerstatusid,@userid=userid from bjsunmis.dbo.customer where customerid=@oldid;
select @finaluserid=userid from users where oldid=@userid
insert into customerotherinfo(customerid,otherpro,customerstatusid,userid)values(@customerid,@otherpro,@statusid,@finaluserid)
fetch next from my_cursor into @customerid,@oldid; --读取下一行数据
end
close my_cursor; --关闭游标
deallocate my_cursor; --释放游标
go
上一篇: Poi-1:个人记录使用过程的问题