没仔细看!如果你要:
随机取10条记录:select top 10 * form 表 order by newid()

解决方案 »

  1.   

    select  @q_no=q_no from #mtemp where mid=@iValue
    改为
    select  @q_no=isnull(q_no,0) from #mtemp where mid=@iValue
    试试
      

  2.   

    主要是这一句:
    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 --有没有结果?很可能没结果!
      

  3.   


    select @istart=min(mid),@iend=max(mid) from #mtemp很显然:@istart=1 @iend=@@identity
    如果#mtemp没记录,才造成@q_no NULL