Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Having so many condition in like operator

Author  Topic 

mazdak78
Starting Member

2 Posts

Posted - 2011-04-22 : 13:08:59
Is that something like this possible in a like operator:

I have a field name title, I want search it with some AND/OR keyword I know we can have this:

select * from table where title like '%key1' AND title like 'key2' OR title like 'key3'

But this is is not what I want cause number of my keywords is dynamic and I want to have something like this:

select * from table where title like 'key1 AND key2 OR key3'

so I can pass like parameter as a single string to it.

Thanks

Mazdak

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-04-22 : 13:15:16
That'd be tough, since you also have to worry about (Like Key1 and Key2) or like key3 versus
like key1 and (like key2 or like key3). A good approach is to use the ParseValues function (search this site for it) that can take you delimited string and turn it into a table that you can join on.

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page
   

- Advertisement -