I apologize if this is a simple question but I feel like there's something fundamental I'm not understanding.
I have the following script:
select @sql =
'select
fld1
,' + @param1 +'
,fld2
from
table
where
column = ''y'''
exec (@sql)
which returns exactly the results I'd expect, but when I change the column in the where clause to a parameter as below:
select @sql =
'select
fld1
,' + @param1 +'
,fld2
from
table
where
@param2 = ''y'''
exec (@sql)
no results are returned at all. Is there a fundamental reason I can't use a parameter in the where clause like this?
Thanks
@param1differently than@param2? Why did you do that?