Reputation: 203
I'm wondering if it is possible to exclude a value inside a range defined by "between".
Here is an example:
...
WHEN left(name,2) between 'AA' and 'AZ' then 'HALLO'
...
I want to exclude from this range, for example, the value 'AM' Is there a short way to obtain this or I need to split the range into two different ones as follow?
...
WHEN left(name,2) between 'AA' and 'AL' then 'HALLO'
WHEN left(name,2) between 'AN' and 'AZ' then 'HALLO'
...
Thanks in advance.
Upvotes: 1
Views: 1313
Reputation: 263803
You it is possible:
...
WHEN (left(name,2) between 'AA' and 'AZ') AND (left(name,2) <> 'AM')
then 'HALLO'
...
Upvotes: 1
Reputation: 71939
WHEN left(name,2) between 'AA' and 'AZ' AND NOT left(name,2) = 'AM' then 'HALLO'
Upvotes: 2
Reputation: 56935
Just put your more restrictive case first:
CASE
WHEN left(name,2) == 'AM' then 'wohoo'
WHEN left(name,2) between 'AA' and 'AZ' then 'HALLO'
END
If it matches 'AM' then since that case is first in the statement, its action will be taken, even though the second case also matches 'AM'.
Upvotes: 3