August 10, 2007 at 4:21 am
Hi,
I have a 'Search' field and radio-set (include any of these words / all of these words) on the page.
If the following is entered "word1 word2 word3" is it possible within T-SQL to successfully return the relevant rows ?
The search is against just 1 field in a table
Does the 'search' string have to be split up and a select run 3 times if 3 words are entered ?
Any help would be appreciated.
Thank you
Lee
August 10, 2007 at 9:01 am
Search string has to be split into words, but these words can be searched within one statement with AND or OR, as appropriate.
SELECT product_id
FROM products
WHERE description LIKE '%screen%' OR description LIKE '%monitor%' OR description LIKE '%computer%'
This will work for CHAR/VARCHAR columns. But maybe in your case it would be more appropriate to use full-text search features?
August 10, 2007 at 1:20 pm
This will allow to handle any number odf words:
SELECT product_id, description
FROM products P
INNER JOIN @SplitWords S ON P.description LIKE '%' + SearchWord + '%'
GROUP BY product_id, description
_____________
Code for TallyGenerator
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply