ok basically what i would like is to check 32 variables thats ive already declared.
I would like to loop through this variables checking there values
rather tyhen writing if statements for each variables
the variables are called market1..........market32
so my aim was to create a loop
example
while i< 32
begin
declare @variable varchar(2000)
set @variable = 'market'+ i
if @variable = 'example'
blah blah blah
""
""
end
the best way i reckon would be like this
while i< 32
begin
declare @variable varchar(2000)
declare @sql varchar(2000)
set @variable = 'market'+ i
set @sql = 'declare x varchar(2000)'
+ ' c = ' + @variable
blah blah blah
""
""
end
exec(@sql)
but it always asks for @market1 to be declared i cant declare it again as i will lose it value
Rather than declare 32 variables, why don't you try creating a temp table with an identity column and inserting the 32 values into that. You could then loop through that table, selecting each value in turn into a single holder variable and do whatever you need to.
yeh i know but was tryna keep it dynamic with less code...
basically tryan be to cleaver for me own good
thanks ne hows mate rerally appriciate your time..
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.