SQL中游标嵌套循环的示例

SQL中经常要用到循环,下面就将为您介绍SQL中游标嵌套循环的示例,供您参考,希望对您学习SQL的循环有所帮助。

create table #temp(a int,b int)

insert into #temp
select 1,2
insert into #temp
select 3,4
select * from #temp
declare @i int,
   @j int
declare cur1 cursor for
select a from #temp
open cur1
fetch cur1 into @i
while @@fetch_status =0
begin
select 'cur1:',@i
declare cur2 cursor for
   select b from #temp
open cur2
fetch cur2 into @j
while @@fetch_Status =0
begin
   select 'cur2:',@j
   fetch cur2 into @j
end
close cur2
deallocate cur2
fetch cur1 into @i
end
close cur1
drop table #temp
deallocate cur1

【编辑推荐】

sql循环插入的语句写法

SQL循环语句的妙用

SQL中CONVERT函数详解

SQL中DateDiff函数的使用

删除SQL约束的方法

当前题目:SQL中游标嵌套循环的示例
当前地址:http://www.hantingmc.com/qtweb/news25/475325.html

网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等

广告

声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源: 创新互联