SQL CASE statement is a conditional flow that returns a value when the first condition is met (like an IF-THEN-ELSE statement). 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.
If there is no ELSE part and none of the conditions are true, it returns NULL value.
Let us consider a demo database with table name Persons.
The following Query executes through conditions and returns a value when the first condition is met:
Figure 47.1. PERSONS TABLE
Figure 47.2 QUERY OUTPUT
Want More SQL Deep Dives