I have simplified a longer query to this.
I would like to use a pre-declared variable in another variable declaration. This is what I have done.
DECLARE @FRUIT VARCHAR(10) = 'apple'
DECLARE @sql3 NVARCHAR(MAX) = CONCAT('select ', @FRUIT)
EXEC(@sql3)
I was expecting it to give me the result as 'apple' - but I get this error instead:
Invalid column name 'apple'.
Please suggest a way how to solve this. Thanks