MsSql, where fieldname IN LIKE (LIST)

I was looking for some time and, unfortunately, I can not find a solution for this.

Basically I have a string of comma-separated keywords that I successfully converted to a list using a function that takes @String and returns TABLE (varchar value (30)). So far so good.

Now I can use this list in the where clause, as shown below:

SELECT project.*
FROM Projects project 
WHERE project.title IN (SELECT * FROM dbo.ParamsToList('.net,test'))

This matches where project.title is exactly (equal to) any of the keywords (.net or test).

I need a match where the LIKE header is '%' + any-keyword + '%'.

Any help would be greatly appreciated.

thank

+3
source share
2 answers

One of the methods:

SELECT project.*
FROM Projects project 
WHERE EXISTS
    (
        SELECT * FROM dbo.ParamsToList('.net,test') x 
        WHERE project.title LIKE '%' + x.value + '%'
    )

, , .

+5

JOINING

SELECT DISTINCT project.*
FROM   Projects project
       INNER JOIN dbo.ParamsToList('.net,test') pl ON project.title LIKE '%' + pl.Value + '%'
+2

All Articles