CASE

<< Click to Display Table of Contents >>

Navigation:  Data Module > Import & export > Data mappings > SQL Basics > Functions >

CASE

Evaluates a list of conditions and returns one of the possible result expressions.

 

Syntax

The simple CASE function compares an expression to a set of simple expressions to determine the result.

CASE  

 WHEN when_expression THEN result_expression

   [ ...n ]

 [

   ELSE else_result_expression

 ]

END

 

Arguments

when_expression - Is a simple expression to which input_expression is compared when using the simple CASE format. when_expression is any valid expression. The data types of input_expression and each when_expression must be the same or must be an implicit conversion.

result_expression - Is the expression returned when input_expression equals when_expression evaluates to TRUE, or Boolean_expression evaluates to TRUE. result expression is any valid expression.

else_result_expression - Is the expression returned if no comparison operation evaluates to TRUE. If this argument is omitted and no comparison operation evaluates to TRUE, CASE returns NULL. else_result_expression is any valid expression. The data types of else_result_expression and any result_expression must be the same or must be an implicit conversion.

 

Examples

SELECT started_at, CASE started_at

   WHEN 0.01 THEN 'low'

   WHEN 1 THEN 'good'

   WHEN 10 THEN 'high'

   ELSE 'Unknown'

END

FROM [auction_info]

 

SELECT started_at, CASE

   WHEN started_at < 1 THEN 'low'

   WHEN started_at < 10 THEN 'good'

   WHEN started_at > 10 THEN 'high'

   ELSE 'Unknown'

END

FROM [auction_info]