嗯、谢谢啊、顺便问下 游标里如果没有值、怎么控制下让它关闭?DECLARE cur_plan_detail cursor for select c.question_no_b,c.point_per, c.difficult_y,c.difficult_z,c.difficult_n,c.type from t_test_plan a,t_test_paper_question_b c where a.id = c.plan_id and a.id = p_plan_id order by question_no_b
open cur_plan_detail if @@FETCH_STATUS <>0 close cur_plan_detail
检查@@fetch_status = 0 完整示例 declare cur_temp cursor local for select aa from bb where ..... open cur_temp Fetch next from cur_temp into @aa while @@fetch_status = 0 begin 数据处理..... Fetch next from cur_temp into @aa end close cur_temp Deallocate cur_temp
DECLARE cur_plan_detail cursor for select c.question_no_b,c.point_per, c.difficult_y,c.difficult_z,c.difficult_n,c.type from t_test_plan a,t_test_paper_question_b c where a.id = c.plan_id and a.id = p_plan_id order by question_no_b fetch next... while @@FETCH_STATUS=0 begin ... fetch next... end --游标大致这个格式循环,不过能不用游标最好别用!貌似这是军令,PS你儿子好可爱
--sql2008
declare @i int=0
select
c.question_no_b,c.point_per, c.difficult_y,c.difficult_z,c.difficult_n,c.type
from t_test_plan a,t_test_paper_question_b c
where a.id = c.plan_id
and a.id = p_plan_id
order by question_no_b
if @@FETCH_STATUS <>0
close cur_plan_detail
declare cur_temp cursor local for
select aa
from bb
where .....
open cur_temp
Fetch next from cur_temp into @aa
while @@fetch_status = 0
begin
数据处理.....
Fetch next from cur_temp into @aa
end
close cur_temp
Deallocate cur_temp
DECLARE cur_plan_detail cursor for
select
c.question_no_b,c.point_per, c.difficult_y,c.difficult_z,c.difficult_n,c.type
from t_test_plan a,t_test_paper_question_b c
where a.id = c.plan_id
and a.id = p_plan_id
order by question_no_b
fetch next...
while @@FETCH_STATUS=0
begin
...
fetch next...
end
--游标大致这个格式循环,不过能不用游标最好别用!貌似这是军令,PS你儿子好可爱