Nested 'CASE' statement in 'ELSE' clause could be flattened
6 ci.relname AS index_name,
7 CASE i.indisclustered
8 WHEN TRUE THEN 1
9 ELSE CASE am.amname10 WHEN 'hash' THEN 2
11 ELSE 3
12 END
Description
Nested CASE
statement in ELSE
clause could be flattened.
Bad practice
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
Recommended
SELECT
CASE
WHEN species = 'Cat' THEN 'Meow'
WHEN species = 'Dog' THEN 'Woof'
END AS sound
FROM mytable