set @j=1 --赋初值
while @j<=@n
begin
set @find=1--赋初值find=1
set @already=0--赋初值already=0
while @find>1
begin
exec control_qchar @q_cha output --随机产生一个章节
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 @istart=min(mid),@iend=max(mid) from #mtemp --赋初值@istart,@iend
/*保证iValue位于iStart和iEnd之间*/
set @iValue = CONVERT(INT,RAND() * (@iEnd - @iStart + 1) + @iStart)/*产生随机数*/
select @q_no=q_no from #mtemp where mid=@iValue
select @already=count(*) from s_temptable where (q_type=@q_type
and q_no=@q_no and s_xh=@xh)
if @already=0 set @find=0
drop table #mtemp
end
insert into s_temptable(s_xh,q_no,q_type)values (@xh,@q_no,@q_type)
set @j=@j+1
每次运行都说我的@q_no为null?
我该如何改写?
主要是这一句:
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 --有没有结果?很可能没结果!