CASE is SQL's if/else. It is how you clean messy values, sort numbers into bands, build flags, and count several things in one query.
This guide covers the whole of it. How CASE decides. Both forms of the syntax. The two rules that break a CASE with no error message at all, one about order and one about NULL. Everywhere in a query a CASE is allowed to go. And how a real cleaning rule gets built, on real data, mistakes included.
What CASE is and how it decides
CASE produces one value per row by checking a list of tests top to bottom:
WHEN <test 1> THEN <value 1>






