Case

Summary

The CASE statement chooses from a sequence of conditions, and executes a corresponding statement.

Syntax

CASE (WHEN <logical expression> THEN <arithmetic expression>)
[ELSE <arithmetic expression>]
END 

Details

In the following examples, the call to the AllTypes() function returns a table containing the metadata for the different data types available to Xactly Connect.

 

Examples

/* Example 1: Single check */
SELECT integer1,
CASE WHEN integer1 > 5
   THEN 'Greater than 5!'
   ELSE 'Less than or equal to 5'
END
FROM AllTypes();
  
/* Example 2: Multiple checks */
SELECT integer1,
CASE WHEN integer1 > 5 AND integer1 <= 8
   THEN 'Greater than 5 and less than or equal to 8!'
      WHEN integer1 >= 9
      THEN 'Greater than or equal to 9!'
      ELSE 'Not a value in our range.'
END
FROM AllTypes();
  
/* Example 3: Nested CASE */
SELECT integer1,
CASE WHEN integer1 >= 5
   THEN CASE WHEN integer1 = 5
      THEN 'FIVE'
      ELSE 'Greater than 5'
      END
   ELSE 'Not a value in our range.'
END
FROM AllTypes();

Related Functions

IF-THEN-ELSE