SQL Server 2008 Multiple LIKE Issues

I am using MS SQL 2008, and now I am facing a problem for several days. My SP parameter can contain one to three words per line (nvarchar), and I have to return the corresponding entries LIKE %phrase%for each word in the line.

Example. My parameter:

"stack overflow"

Entries to be returned:

miSTACKon
noOVERFLOWon
STACKit
poOWERFLOW
STACK
OWERFLOW

I also looked at the FTS function, but CONTAINS accepts only one wildcard at the end of (each) phrase

phrase*

Is there a solution to this problem besides dynamic SQL?

+3
source share
2 answers

, - " alls"

   select distinct Record from dbo.Records
     inner join dbo.Split('stack overflow', ' ') tokens 
       on records_table.Record like '%' + tokens.value + '%'

, , , "", dbo.Split, varchars "" "", "".

select distinct Name from (
 select 'stack' as Name
 union all
 select 'nope' as Name
 union all
 select ' stackoverflow' as Name
   ) records_table 
   inner join (
   select 'stack' as value
     union all
    select 'overflow' as value) tokens 
    on records_table.Name like '%' + tokens.value + '%'

:

stack
stackoverflow

dbo.Split, ...

+6

"" (.. ",", "|" ..), "" ( ), , , JOIN, LIKE '%' + word + '%'.

0

Source: https://habr.com/ru/post/1762527/


All Articles