SqlServer中循环查询结果集


declare @id int,@value nvarchar(100);
begin
declare c_test_main cursor fast_forward for select hps_hpId,hps_time from hospitalPermSupp where hps_usId=1;
open c_test_main;--打开游标
while 1=1 --开始循环
begin
fetch next from c_test_main into @id,@value; --赋值到变量中
if(@@fetch_status!=0)break;--如果没有结果退出循环
select @id as a,@value as b
end
close c_test_main --关闭游标
deallocate c_test_main --释放游标
end


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM