CASE
statements in ELSE
clause SQL-L058Nested CASE
statement in ELSE
clause could be flattened.
In this example, the outer CASE
’s ELSE is an unnecessary, nested CASE
.
SELECT
CASE
WHEN species = 'Cat' THEN 'Meow'
ELSE
CASE
WHEN species = 'Dog' THEN 'Woof'
END
END as sound
FROM mytable
SELECT
CASE
WHEN species = 'Cat' THEN 'Meow'
WHEN species = 'Dog' THEN 'Woof'
END AS sound
FROM mytable