Question

Is there a way to do something like this? (This is pseudo code)

      CASE(@P1) 
        WHEN 'a' or 'd' or 'z' THEN 1
        WHEN 'b' or 't' THEN 2
        ELSE 0 

The idea being that I can check multiple values that should return the same value. i.e. 'a' returns 1 and 't' returns 2

Was it helpful?

Solution

select CASE WHEN @P1 in ('a', 'd', 'z') THEN 1
            WHEN @P1 in ('b', 't') THEN 2
            ELSE 0 
       END
from your_table

or

select CASE WHEN @P1 = 'a' or @P1 = 'd' or @P1 = 'z' THEN 1
            WHEN @P1 = 'b' or @P1 = 't' THEN 2
            ELSE 0 
       END
from your_table
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top