Morning Man
Morning Man

Reputation: 13

How do I write a CASE with 2 conditions and an OR statement inside the second condition?

I am using SQL and trying to write a CASE statement with two conditions, where the second condition has an OR.

I have tried using OR for this condition but it is not working, I have also tried using the IN function but that does not seem to support '%' Wild Cards.

CASE
    WHEN 'Column1' LIKE '%a%' AND 'Column1' NOT LIKE '%b%' OR '%c%' THEN 
         'NewValue'
END 




CASE 
    WHEN 'Column1' LIKE '%a%' AND 'Column1' NOT IN ('%b%', '%c%') THEN 
         'NewValue'

Upvotes: 1

Views: 52

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1270463

LIKE is a binary operator. You need to include both every time it is used. And then you need parentheses. However, you probably intend:

(CASE WHEN 'Column1' LIKE '%a%' AND
           'Column1' NOT LIKE '%b%' AND
           'Column1' NOT LIKE '%c%'
      THEN 'NewValue'
 END)

Upvotes: 1

Related Questions