b00kgrrl
b00kgrrl

Reputation: 597

How to use SQL CONTAINS or LIKE with multiple arguments

I'd like to use the SQL LIKE or CONTAINS operator with multiple arguments. Is there a way to do this efficiently, or does each instance of LIKE have to be separated by OR?

WHEN postal_zip_code_permanent like ('A', 'B', 'C', 'E', 'G', 'H', 'J', 'R', 'S', 'T', 'V', 'X', 'Y') THEN 'Canada, outside Ontario'

Upvotes: 0

Views: 764

Answers (1)

Werner Henze
Werner Henze

Reputation: 16726

In your simple case you can use IN instead of LIKE

WHEN postal_zip_code_permanent IN ('A', 'B', 'C', 'E', 'G', 'H', 'J', 'R', 'S', 'T', 'V', 'X', 'Y') THEN 'Canada, outside Ontario'

If you really need LIKE, you need to write

WHEN postal_zip_code_permanent LIKE 'A%' OR postal_zip_code_permanent LIKE 'B%' THEN ...

Upvotes: 4

Related Questions