Usecases of CASE expression
- When there are complex conditions, where result is depending on multiple columns.
- When we have a specific order of condition to get executed.
- When we want to create a dummy table with transformed values for analysis purposes.
- When we apply aggregation on different cases.
SQL Server CASE Expression
The CASE expression is used to show another column which can be evaluated based on the conditions depending on the existing columns. The CASE expression consists of WHEN and THEN statements. WHEN is used when the condition satisfies and THEN executes the operation or assignment of value of that column based on the evaluation of the expression. The CASE statement can contain multiple WHEN and THEN statements based on the conditions. The THEN can also contain the ELSE statement if the condition in THEN is not satisfied then the ELSE statement will be assigned.