TSQL: Variable scope and EXEC()

Posted by Joel on Stack Overflow See other posts from Stack Overflow or by Joel
Published on 2009-03-24T15:34:51Z Indexed on 2010/04/21 9:13 UTC
Read the original article Hit count: 311

Filed under:
|
|
declare @test varchar(20)
set @test = 'VALUE'

exec('
select '+@test+'
')

This returns:

Invalid column name 'VALUE'.

Is there an alternate method to display the variable value on the select statement?

© Stack Overflow or respective owner

Related posts about tsql

Related posts about sql-server