SQL SERVER中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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值