lmu92 (1/5/2010)
dbuendiab (1/5/2010)
I think you have already several good answers, or at last the kind I would have suggested before this one. Despite of this, and only as a alternative to consider, you could concatenate the string fields before LIKE comparison (you'll can't expect high performance, I guess):Select *
From Table
Where col1 + col2 + col3 like '%' + 'SearchedString' + '%'
You need to make sure to separate each column. Otherwise you might get wrong results.
DECLARE @t TABLE (col1 varchar(10), col2 varchar(10) ,col3 varchar(10))
INSERT INTO @t values('book shelf','red','Mike')
Select *
From @t
Where col1 + col2 + col3 like '%' + 'fred' + '%'
-- versus
Select *
From @t
Where col1 + '_' + col2 + '_' + col3 like '%' + 'red' + '%'
I agree, the proposed query depends on the data, but if you are cautious on it it can be a 'quick & dirty' approach.