0

I'm using SQL Like operator in asp for my project, and I want to obtain all the results that have the words that I inserted in the search field.

So, if I search "fish restaurant", I'd like to obtain all the restaurants that have both "fish" and "restaurant" in the fields I'm searching.

So far, my code is as follow:

sql = "SELECT dbo.tbl_activity where (name like '%"&MySearchCriteria&"%' OR  description like '%"&MySearchCriteria&"%' OR  metadescription like '%"&MySearchCriteria&"%' OR  products like '%"&MySearchCriteria&"%' OR brand like '%"&MySearchCriteria&"%') "&QueryAdd&" Order By Nome"

is it a way to achieve what I'm trying to do?

1 Answer 1

2

Your approach is fine.

However you can make the query a bit more pleasant to read like this:

SELECT  *
FROM    tbl_activity
WHERE   CONCAT_WS(' ', name, description, ...) LIKE '%fish%'
AND     CONCAT_WS(' ', name, description, ...) LIKE '%restaurant%'
AND     ... 

...and so on for each word in your search field

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.