SQL 如何在存储过程中增加一个值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13947472/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
how to increment a value inside stored procedure
提问by Prathiesh
How to increment a value of local variable in the loop inside a stored procedure
如何在存储过程内的循环中增加局部变量的值
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
the values like @x
and @y
is not incrementing and I am stuck in an infinite loop.
像@x
和这样的值@y
没有增加,我陷入了无限循环。
回答by alzaimar
you have to enclose the while-body in a begin-end block.
您必须将 while-body 包含在开始结束块中。
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
I do not understand what you are trying to achive (besides the fact that you want to increase some variables)
我不明白你想要达到什么(除了你想增加一些变量的事实)