WHEN (Entity SQL)

Evaluates one or more Boolean expressions.

WHEN when_expression THEN then_expression

Arguments

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

Return Type

A Boolean value.

Remarks

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 (Entity SQL).

Example

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 (EntityClient).

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

CASE WHEN AVG({25,12,11}) < 100 THEN TRUE ELSE FALSE END

This example produces the following output:

Value: True

See Also

Reference

THEN (Entity SQL)
CASE (Entity SQL)

Concepts

Entity SQL Reference

Other Resources

Case Expression