Select Column1 From Table Where @Variable Like \'%\' + Column2 + \'%\'
Doesn\'t seem to work how I thought it would. Any suggestions?
If you have a limited number of columns, you can use case
:
where case
when @Variable = 'col1' then col1
when @Variable = 'col2' then col2
when @Variable = 'col3' then col3
...
end like '%' + Column2 + '%'
Another option is dynamic SQL:
declare @sql nvarchar(max)
set @sql = 'Select Column1 From Table Where ' + @Variable +
' Like ''%'' + Column2 + ''%'''
exec (@sql)