
Returns result_expression of the first Boolean_expression that evaluates to TRUE. If no input_expression = when_expression evaluates to TRUE, the SQL Server Database Engine returns the else_result_expression if an ELSE clause is specified, or a NULL value if no ELSE clause is specified.Įvaluates, in the order specified, Boolean_expression for each WHEN clause. Returns the result_expression of the first input_expression = when_expression that evaluates to TRUE. In the order specified, evaluates input_expression = when_expression for each WHEN clause. If these expressions are equivalent, the expression in the THEN clause will be returned. The simple CASE expression operates by comparing the first expression to the expression in each WHEN clause for equivalency. For more information, see Data Type Precedence (Transact-SQL). Returns the highest precedence type from the set of types in result_expressions and the optional else_result_expression. To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation. Boolean_expression is any valid Boolean expression. The Boolean expression evaluated when using the searched CASE format. The data types of else_result_expression and any result_expression must be the same or must be an implicit conversion.

else_result_expression is any valid expression. If this argument is omitted and no comparison operation evaluates to TRUE, CASE returns NULL. The expression returned if no comparison operation evaluates to TRUE.

result expression is any valid expression. The expression returned when input_expression equals when_expression evaluates to TRUE, or Boolean_expression evaluates to TRUE. The data types of input_expression and each when_expression must be the same or must be an implicit conversion. WHEN when_expressionĪ simple expression to which input_expression is compared when the simple CASE format is used. input_expression is any valid expression. The expression evaluated when the simple CASE format is used.

WHEN Boolean_expression THEN result_expression WHEN when_expression THEN result_expression Syntax for SQL Server, Azure SQL Database and Azure Synapse Analytics. For example, you can use CASE in statements such as SELECT, UPDATE, DELETE and SET, and in clauses such as, IN, WHERE, ORDER BY, and HAVING. The searched CASE expression evaluates a set of Boolean expressions to determine the result.īoth formats support an optional ELSE argument.ĬASE can be used in any statement or clause that allows a valid expression. The simple CASE expression compares an expression to a set of simple expressions to determine the result. Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics Analytics Platform System (PDW) SQL Endpoint in Microsoft Fabric Warehouse in Microsoft FabricĮvaluates a list of conditions and returns one of multiple possible result expressions.
