Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Dynamic variable creation

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-07-19 : 21:12:02
Andrew writes "I tried to send this once before but I messed it up. Here goes..

SQL 7.0 SP 3
NT 4.0 SP 6a

I need to create T-SQL variables at run-time. The amount of variables that I need to create is not known until run-time. So essentially, I need a DECLARE statement, in a loop, that creates then necessary number of variables.

Something like this...

WHILE @counter > 0 --@counter is not known until run-time
BEGIN
DECLARE @test + @counter VARCHAR(10) --This fails because I suck
SET @counter = @counter - 1
END

Any help, ideas or direction would be much appreciated...

Thanks

Andrew"
   

- Advertisement -