Bird
0
0

Identify the error in this Simple CASE query:

medium📝 Debug Q14 of 15
SQL - CASE Expressions
Identify the error in this Simple CASE query:
SELECT ProductName,
CASE ProductCategory
WHEN 'A' THEN 'Category A'
WHEN 'B' 'Category B'
ELSE 'Other'
END AS CategoryName
FROM Products;
ACASE expression should be inside parentheses.
BMissing END keyword at the end.
CIncorrect use of ELSE keyword.
DMissing THEN keyword after WHEN 'B'.
Step-by-Step Solution
Solution:
  1. Step 1: Review each WHEN clause syntax

    WHEN clauses must have THEN keyword before the result. The second WHEN is missing THEN.
  2. Step 2: Check other parts of the query

    END keyword is present, ELSE is correctly used, parentheses are not required around CASE expression.
  3. Final Answer:

    Missing THEN keyword after WHEN 'B'. -> Option D
  4. Quick Check:

    WHEN must be followed by THEN [OK]
Quick Trick: Each WHEN must be followed by THEN [OK]
Common Mistakes:
  • Forgetting THEN after WHEN
  • Thinking END is optional
  • Adding unnecessary parentheses

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes