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)
 Dynamically assigning variable names

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-06-12 : 22:25:44
Rob writes "Hi,

Is it possible to dynamically generate variable names and get the values from them ?

If I have the following:

declare @q1 smallint
declare @q2 smallint
declare @i int
declare @j varchar(4)

select @q1 = 10 -- assume @q1 & q2 is passed into
select @q2 = 20 -- a stored proc
-- q3 .....
-- q4 .....
-- ........

--Set Counter
Select @i = 1

select @j = "@q" + convert(varchar(2), @i)
--I want to get the value of the result of @j (ie: @q1 = 10)
-- increment counter
-- loop through other variable .....

The reason for this is I want to loop through all the variable and get thier values without passing in the variable name each time.

Any ideas ??
Thanks,"
   

- Advertisement -