I have a problem when I would like to transfer the value of a variable to another variable.
declare @column varchar(255);
set @column = 'cheesecake';
declare @tmp varchar(255);
set @tmp = (select @column from TEST where id = 1);
But in this case @tmp
won't have the value of the table, but the name of the @column
variable. I tried it with dynamic sql, but I got a syntax error.
declare @column varchar(255);
set @column = 'cheesecake';
declare @tmp varchar(255);
set @tmp = exec('select ' + @column + ' from TEST where id = 1');
How can I solve that the @tmp
variable would contain the value of the query?