如何在存储过程中添加循环中局部变量的值
ALTER PROC [dbo].[Usp_SelectQuestion]
@NoOfQuestion int
AS
BEGIN
Declare @CNT int
Declare @test int
Declare @x int
Declare @y int
set @x = 1;
set @y = 1;
Select @CNT=(Select Count(*) from (select Distinct(setno)from onlin) AS A)
select @test=@NoOfQuestion/@CNT
while @x <= @CNT do
while @y <= @test
select * from onlin where setno = @x
set @y = @y +1
set @x =@x + 1
END
诸如@x
和@y
之类的值没有增加,我被困在无限的环路中。
您必须将while-boty包裹在开始时块中。
while @x <= @CNT do begin
while @y <= @test begin
select * from onlin where setno = @x
set @y = @y + 1
end
set @x =@x + 1
end
我不明白您想实现的目标(除了要增加一些变量的事实)