SQL - CASE WHEN OR THEN ELSE END => the OR is not supported

SQL - CASE WHEN OR THEN ELSE END => the OR is not supported

SQL, SQL Server

This is a common error when you are attempting to use an OR to satisfy multiple conditions in a WHEN statement. "The OR in the WHEN clause of a CASE statement is not supported."

 

Consider this SQL which currently gives the "The OR in the WHEN clause of a CASE statement is not supported" error:

CASE ebv.db_no 
    WHEN 22978 OR 23218 OR 23219 THEN 'WECS 9500' 
    ELSE 'WECS 9520' 
END as wecs_system 

Solution 1:

CASE ebv.db_no 
  WHEN 22978 THEN 'WECS 9500' 
  WHEN 23218 THEN 'WECS 9500'  
  WHEN 23219 THEN 'WECS 9500' 
  ELSE 'WECS 9520' 
END as wecs_system 

Solution 2:

CASE  
  WHEN ebv.db_no IN (22978, 23218, 23219) THEN 'WECS 9500' 
  ELSE 'WECS 9520' 
END as wecs_system