Evaluates one or more Boolean expressions.

WHEN when_expression THEN then_expression


  • when_expression
    Any valid Boolean expression.
  • then_expression
    Any valid query expression that returns a collection.

Return Type

A Boolean value.


Use WHEN to evaluate one or more Boolean expressions. If there are multiple when_expressions, the first when_expression that evaluates to true yields the corresponding Then_expression. The remaining expressions are not evaluated. If none of the WHEN conditions are satisfied, the else-expression is evaluated. However, if there is no else-expression, the result is null.

For an example, see CASE.


The following Entity SQL query uses the CASE expression to evaluate a set of Boolean expressions in order to determine the result. The query is based on the AdventureWorks Sales Model. To compile and run this query, follow these steps:

  1. Follow the procedure in How to: Execute a Query that Returns PrimitiveType Results.

  2. Pass the following query as an argument to the ExecutePrimitiveTypeQuery method:

CASE WHEN AVG({@score1,@score2,@score3}) < @total THEN TRUE ELSE FALSE END

See Also




Entity SQL Reference