APPLIES TO: SQL Server Azure SQL Database Azure SQL Data Warehouse Parallel Data Warehouse Evaluates a list of conditions and returns one of multiple possible result expressions. The CASE expression cannot be used to control the flow of execution of Transact- SQL statements, statement blocks, user-defined functions, and stored procedures. Eine Liste der Methoden zur Ablaufsteuerung unter Control-of-Flow Language (Transact- SQL ) (Sprachkonstrukte zur Ablaufsteuerung (Transact- SQL )). The CASE statement goes through conditions and returns a value when the first condition is met (like an IF-THEN-ELSE statement).
So, once a condition is true, it will stop reading and return the result. If no conditions are true, it returns the value in the ELSE clause. Come on Microsoft time to grow up from the toy database status. You can use CASE expressions anywhere in the SQL queries.
CASE expressions can be used within the SELECT statement, WHERE clauses, Order by clause, HAVING clauses, Insert, UPDATE and DELETE statements. Best way to do nested case statement logic in SQL. This SQL Server tutorial explains how to use the SQL Server (Transact- SQL ) CASE statement with syntax and examples. In SQL Server (Transact- SQL ), the CASE statement has the functionality of an IF-THEN-ELSE statement.