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