L lo5750ul Senior member Jul 18, 2001 744 0 76 Jun 4, 2002 #1 Hey all, I would like to do a simple counter loop in an SQL Stored Procedure. I am passing a variable in to the SP and I want to count from 1 to the variable. Does anyone know how to do it? Cheers.
Hey all, I would like to do a simple counter loop in an SQL Stored Procedure. I am passing a variable in to the SP and I want to count from 1 to the variable. Does anyone know how to do it? Cheers.
S SQL Member Jul 10, 2001 115 0 0 Jun 4, 2002 #2 Several ways depending on which database. Stripped down SQL Server: declare @count int select @count=1 while(@count<=@var1) begin print @count -- or select @count works as well select @count=@count+1 end
Several ways depending on which database. Stripped down SQL Server: declare @count int select @count=1 while(@count<=@var1) begin print @count -- or select @count works as well select @count=@count+1 end
L lo5750ul Senior member Jul 18, 2001 744 0 76 Jun 5, 2002 #3 SQL, Thanks for the reply. I had worked that bit out. The next question is, how do you take the counter and create a variable name with it. e.g. DECALRE @strInput + count to end up as @strInput1, @strInput 2 etc.
SQL, Thanks for the reply. I had worked that bit out. The next question is, how do you take the counter and create a variable name with it. e.g. DECALRE @strInput + count to end up as @strInput1, @strInput 2 etc.