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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
cmsjr has a point about not needing exec for this. But assuming you’re posting a simplified version of the problem and exec is a requirement:
There’s no column named ‘value’ because there’s no table. If you just want it to print
value, you need to encase it in quotes so it looks like a string literal inside the call to exec: