How to use LIKE and IN combined???

  • Hi everybody,

    I would like to write something like:

    ...

    where Temp1 not like %abc% and not like and not like %dae% ... etc.

    Is there any way to combine the LIKE and the IN as the title says?

    Thank you!

    Teo

  • You mean something like this?

    ;WITH TableRows AS (

    -- Some sample data, let's assume

    -- that it comes from your table

    SELECT *

    FROM (

    VALUES ('Some Value Here'),

    ('abc'),

    ('Another Row'),

    ('Film')

    ) AS TableRows(value)

    ),

    Patterns AS (

    -- The patterns to match

    SELECT *

    FROM (

    VALUES ('abc'),

    ('dae'),

    ('fgh'),

    ('ilm')

    ) AS Patterns(p)

    )

    SELECT *

    FROM TableRows

    WHERE NOT EXISTS (

    SELECT 1

    FROM Patterns

    WHERE value LIKE '%' + p + '%'

    )

    Edit: code formatting and comments

    -- Gianluca Sartori

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply