I\'m building a simple search algorithm and I want to break my string with spaces, and search my database on it, like so:
$
This will works perfectly in both cases, one or multiple fields searching multiple words.
Hope this will help someone. Thanks
declare @searchTrm varchar(MAX)='one two three four';
--select value from STRING_SPLIT(@searchTrm, ' ') where trim(value)<>''
select * from Bols
WHERE EXISTS (SELECT value
FROM STRING_SPLIT(@searchTrm, ' ')
WHERE
trim(value)<>''
and(
BolNumber like '%'+ value+'%'
or UserComment like '%'+ value+'%'
or RequesterId like '%'+ value+'%' )
)