Which of the following correctly demonstrates the syntax of a searched CASE expression in SQL?
easy📝 Syntax Q3 of 15
SQL - CASE Expressions
Which of the following correctly demonstrates the syntax of a searched CASE expression in SQL?
ACASE WHEN condition1 THEN result1 WHEN condition2 THEN result2 END ELSE result3
BCASE expression WHEN value1 THEN result1 WHEN value2 THEN result2 ELSE result3 END
CCASE WHEN condition1 THEN result1 ELSEIF condition2 THEN result2 ELSE result3 END
DCASE WHEN condition1 THEN result1 WHEN condition2 THEN result2 ELSE result3 END
Step-by-Step Solution
Solution:
Step 1: Identify searched CASE syntax
Searched CASE uses WHEN conditions followed by THEN results, ending with END.
Step 2: Check options
CASE WHEN condition1 THEN result1 WHEN condition2 THEN result2 ELSE result3 END correctly shows multiple WHEN conditions with THEN results and an ELSE clause before END.
Final Answer:
CASE WHEN condition1 THEN result1 WHEN condition2 THEN result2 ELSE result3 END -> Option D
Quick Check:
Is the ELSE clause before END and conditions after WHEN? [OK]
Quick Trick:WHEN conditions THEN results, ELSE optional, END mandatory [OK]
Common Mistakes:
Using ELSE outside END
Confusing searched CASE with simple CASE syntax
Using ELSEIF instead of multiple WHEN
Master "CASE Expressions" in SQL
9 interactive learning modes - each teaches the same concept differently