0

I would like a search bar that would look at the input and give all possible solutions rather that only that are matching.

This is for a web-app that displays all item descriptions per SQL db table and matches any or all words . But, I should be able to put in couple of texts and it should display all letters that are matching , Wildcard so to speak

SELECT * FROM [table] WHERE ([name] LIKE '%' + @Name + '%')

I expect the output to give results for any text / strings / numbers matching and display all, but it is only giving certain results . Is there a wildcard that i can add so all matching can display?

Example : Search Bar : John good
Expected O/P:

John is awesome, good and clever
John is good
John is not good

Actual O/P:

Nothing

Search Bar : John is
Expected O/P:

John is awesome, good and clever
John is good
John is not good
John is great

Actual O/P:
John is awesome, good and clever
John is good
John is not good
John is great

PC_Neo
  • 21
  • 1
  • 10

1 Answers1

1

This is how it should be done. lets say that you search for John good.

What you will do then is split it as "John", "good", then your search will look like this instead

SELECT * FROM [table] WHERE ([name] LIKE '% John %') or ([name] LIKE '% good %')

This will give you the result you are intressted in.

Alen.Toma
  • 4,684
  • 2
  • 14
  • 31
  • Thanks Alen, In other words SELECT * FROM [table] WHERE ([name] LIKE '%' + [at]Name + '%') or ([name] LIKE '%' + [at] Name + '%') ?? I want to pass on any number of words and it should produce the results that match those particular strings – PC_Neo Jan 18 '19 at 14:21
  • look att how Google do thair search, here is an article that may help https://stackoverflow.com/questions/23816039/how-do-you-use-t-sql-full-text-search-to-get-results-like-google – Alen.Toma Jan 18 '19 at 14:32