COALESCE is a cool little function whose name/purpose I keep forgetting/confusing with other cool functions.

Anyway: COALESCE returns the first non-null value in a list:

  • PRINT COALESCE(900, NULL, 10, NULL, 40)

The result: 900.

  • PRINT COALESCE(NULL, NULL, 10, NULL, 40)

The result: 10.

Note that at least one value must be non-null. For example:

  • PRINT COALESCE(NULL, NULL, NULL)

will result in an error — "At least one of the arguments to COALESCE must be a typed NULL."