user3953989
user3953989

Reputation: 1929

How to find multiple words in a string in SQL

I want to be able to take a users search input and find records that match in SQL.

I'm currently using Name like '%' + @SearchText + '%' ) which works fine if they enter in the text the correct way.

Example

If they search for "Jaws Revenge" or "Jaws 2 the revenge" or "revenge jaws" they won't get any results. I want it to return 1 result, id #2 from the table below.

Movies Table
---------------------
ID  Name
1   Jaws
2   Jaws 2: The revenge
3   Jaws 3-D
4   Rocky 5000

I've read about full text search but I don't know if that's worth it, the only option, or if there is a more simple solution.

Upvotes: 1

Views: 97

Answers (2)

Feras Al Sous
Feras Al Sous

Reputation: 1083

You can use like '%' + replace(@SearchText, ' ', '%') + '%' in expration

Upvotes: 0

Gordon Linoff
Gordon Linoff

Reputation: 1269603

You can replace spaces with %:

Name like '%' + replace(@SearchText, ' ', '%') + '%' 

Upvotes: 2

Related Questions