Excel → T-SQL › IF
Excel IF to SQL CASE WHEN
A spreadsheet IF is a CASE. Nested IFs are just more WHENs. Do not nest CASE inside CASE unless you must.
CASE
WHEN total_amount > 10000 THEN 'Tier 1'
WHEN total_amount > 1000 THEN 'Tier 2'
ELSE 'Other'
END AS tier
SQL Server also has IIF(test, a, b). Fine for one test. Three bands belong in CASE.
Canonical translation
CASE
WHEN total_amount > 10000 THEN 'Tier 1'
WHEN total_amount > 1000 THEN 'Tier 2'
ELSE 'Other'
END AS tier
Then write it on a ticket
Monday is free. A colleague asks, you type, we mark it.
Clock in free