
IF and IFS Versus CASE WHEN in SQL Compared Side by Side
Translate IF, nested IF, IFS and SWITCH into SQL CASE WHEN, with AND and OR, NULL handling, branch types and what each returns when nothing matches.
Tag
58 posts

Translate IF, nested IF, IFS and SWITCH into SQL CASE WHEN, with AND and OR, NULL handling, branch types and what each returns when nothing matches.

Translate COUNTIF, COUNTIFS, COUNTA and COUNTBLANK into SQL with count star, count of a column and FILTER, and handle distinct counts and blanks correctly.

Translate SUMIF and SUMIFS into SQL with WHERE, GROUP BY and FILTER, including criteria, wildcards, dates, OR conditions and the blank and case traps.

Translate VLOOKUP and XLOOKUP into SQL joins: exact and approximate match, first-match behavior, not-found values, duplicates and which side to keep.

PostgreSQL has two JSON types. What each keeps, drops and costs, measured on 200,000 rows, and the narrow cases where plain json is the right choice.

Store XML whole, shred it into tables, or both? What each engine keeps and loses, what validation you get, and what it costs on 200,000 documents.

The two commands differ in which machine reads the file. See the permission errors, the path errors and the timings, and choose the one that fits.

Question marks in a CSV are lost data, not a display bug. See where the substitution happens, count the damage and decide whether the export is broken.

TSV avoids most quoting because tabs rarely appear in text, but there are three TSV dialects and they disagree. See where each breaks and which to pick.

Comma, semicolon, tab or pipe? Measure how often each appears in real text, see what a decimal comma does to a file, and choose a delimiter with a reason.