In SQL Server, is there a way for nested case statements to ELSE continue the nesting CASE statement?
CASE
WHEN ... then
CASE
WHEN ... THEN
ELSE **[Continue to below WHEN]** END
WHEN ... then
WHEN ... then
ELSE ... END
Wondering if I can keep the code clean by not copy/pasting the proceeding WHEN statements into the nested CASE.
Flatten the nesting. So instead of this:
You have this:
A
CASEexpression (not statement:CASEcannot branch among SQL segments, only return a value) will stop at the first match, so by flattening the nesting and using andANDto tie in the nested conditions you will get the desired behavior.