I want to query a record containing a phrase.
for example: I want the search to return the record: '开发者_运维技巧The needle in the haystack' with the search phrase 'needle haystack'
The query will work if I just have 'needle' or just 'haystack' using like% in the where clause.
Is there a way to search with the phrase 'needle haystack'?
SELECT * FROM table WHERE phrase LIKE '%needle%' AND phrase LIKE '%haystack%'
Replace phrase
with LOWER(phrase)
if you want the search to be case-insensitive (depends on the DB engine and other things, though).
you can also try this
select * from Suppliers where patindex(REPLACE('%' + 'YOUR SEARCH STRING' + '%',' ','%'),CompanyName) > 1
精彩评论