I have a search query where I use the Like
operator to search keyword, now I need to provide user with an option to search as exact phase
or search all words
based on search keywords
Search Keyword = mission to mars
Search Query
Select * from Table` WHERE Title LIKE '%mission to mars%' OR Details LIKE '%mission to mars%'
Now I need to convert this query so that it search for all words from search keywords mission to mars
So my query should be like
Select * from Table` WHERE Title IN ('mission', 'to', 'mars') OR Details IN ('mission, 'to', 'mars')
Can I using any SQL function break the search keyword mission to mars
and convert it into string with each word wrapped in single quote & separated by comma example 'mission', 'to', 'mars'
STRING_SPLIT
could have been the solution but it works in SQL SERVER 2016 & above while I am using SQL 2014.
I can split the keyword from C# it self and pass it as 'mission', 'to', 'mars' to stored procedure also but i am interested if i can split it in T-SQL itself