Ok, I have a table with several column all labeled, column1, column2, etc. I need to loop through them so I have this statement which will loop through and get the first value, then go to colun2, etc
declare @score int
declare @stm nchar(500)
set @score=0
While @score<=50
Begin
Set @score=@score+1
set @stm='select column' + rtrim(convert(char(2),@score))+' from tablename'
exec sp_executesql @stm
if @score>50
Break
else
COntinue
end
My question is, how can I stuff this value from the dynamic sql into a variable such as:
set @newvalue='exec sp_executesql @stm '
Thanks,
Eddie