Partilhar via


ELSE

Imposes conditions on the execution of an Entity SQL statement. The Entity SQL statement (sql_statement) following the Boolean_expression is executed if the Boolean_expression evaluates to true. The optional ELSE keyword is an alternative Entity SQL statement that is executed when the Boolean_expression evaluates to false or null. 

IF(Boolean_expression )ELSE (Boolean_expression )

Arguments

  • Boolean_expression
    A Boolean expression.

    Note

    If the Boolean_expression contains a SELECT statement, the SELECT statement must be enclosed in parentheses.

Return Type

A Boolean expression.

Remarks

IF...ELSE imposes conditions on the execution of an Entity SQL statement. { sql_statement | statement_block } is any valid Entity SQL statement or statement grouping as defined in a statement block. To define a statement block (batch), use the control-of-flow language keywords BEGIN and END. Although all Entity SQL statements are valid in a BEGIN...END block, certain Entity SQL statements should not be grouped together in the same batch (statement block).

For an example, see CASE.

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.

  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

Reference

CASE

Concepts

Entity SQL Reference