select @q_no=q_no from #mtemp where mid=@iValue 改为 select @q_no=isnull(q_no,0) from #mtemp where mid=@iValue 试试
主要是这一句: select identity(int,1,1) as mid, q_no into #mtemp FROM shiti where (q_type=@q_type and q_difficult>@q_difficult-0.51 and q_difficult<@q_difficult+0.51 and q_cha=@q_cha ) --加上: select * from #mtemp --有没有结果?很可能没结果!
select @istart=min(mid),@iend=max(mid) from #mtemp很显然:@istart=1 @iend=@@identity 如果#mtemp没记录,才造成@q_no NULL
改为
select @q_no=isnull(q_no,0) from #mtemp where mid=@iValue
试试
select identity(int,1,1) as mid, q_no into #mtemp FROM shiti where (q_type=@q_type and
q_difficult>@q_difficult-0.51 and q_difficult<@q_difficult+0.51 and q_cha=@q_cha )
--加上:
select * from #mtemp --有没有结果?很可能没结果!
select @istart=min(mid),@iend=max(mid) from #mtemp很显然:@istart=1 @iend=@@identity
如果#mtemp没记录,才造成@q_no NULL