Search results
The SQL CASE Expression. The CASE expression 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.
- Try It Yourself
CASE WHEN Quantity > 30 THEN 'The quantity is greater than...
- The Try-MySQL Editor
SQL Statement: SELECT CustomerName, City, Country FROM...
- Try It Yourself
3 lis 2011 · BEGIN. (SELECT S.FACILITY_KEY, S.PAT_NUMBER, S.A3A_DATE_USER, M.REFERENCE_DATE , RTRIM(P.LAST_NAME) + CASE WHEN RTRIM(P.FIRST_NAME) <> '' THEN ', ' ELSE '' END + RTRIM(P.FIRST_NAME) PATIENT_NAME. ,CASE WHEN P.NURSING_UNIT is not null THEN P.NURSING_UNIT ELSE '' END NURSING_UNIT.
3 wrz 2024 · The CASE expression has two formats: The simple CASE expression compares an expression to a set of simple expressions to determine the result. The searched CASE expression evaluates a set of Boolean expressions to determine the result. Both formats support an optional ELSE argument.
The CASE statement returns the result_1, result_2, or result_3 if the expression matches the corresponding expression in the WHEN clause. If the expression does not match any expression in the WHEN clause, it returns the esle_result in the ELSE clause. The ELSE clause is optional.
16 sty 2024 · Table of Contents. Understanding CASE WHEN Syntax. Basic Syntax: CASE WHEN THEN. CASE WHEN THEN ELSE. Multiple THENs in CASE WHEN. Examples of Using CASE WHEN in Data Analysis. Example 1: Categorizing Data. Example 2: Handling NULL Values. Example 3: Creating Aggregated Columns. Example 4: Marketing Analysis. Example 5: Customer Segmentation.
The CASE expression has two formats: simple CASE expression and searched CASE expression. Both of CASE expression formats support an optional ELSE statement. Because CASE is an expression, you can use it in any clause that accepts an expression such as SELECT , WHERE , GROUP BY , and HAVING .
The ELSE clause is executed if none of the conditions in the CASE statement is matched. Syntax SELECT customer_id, first_name, CASE WHEN condition1 THEN result1 WHEN condition2 THEN result2 -- Add more WHEN conditions and results as needed ELSE else_result END AS alias_name FROM table_name;