COALESCE

Applies to: ✅ Data 360 SQL ✅ Tableau Hyper API

Returns the first of its arguments that isn’t NULL.

Syntax 

1COALESCE(<value>, ...)

Arguments 

Required 

  • <value>: An expression to evaluate. Provide two or more arguments. All arguments must be convertible to a common data type.

Returns 

Returns the first argument that isn’t NULL. Returns NULL only if all arguments are NULL.

Considerations 

  • COALESCE evaluates only the arguments needed to determine the result. COALESCE doesn’t evaluate arguments after the first non-NULL argument.
  • Use COALESCE to substitute a default value for NULL values when displaying retrieved data.

Examples 

Substitute a Default for Null Values 

Return the first non-NULL value and fall back to a placeholder when the earlier values are NULL.

1SELECT COALESCE(NULL, 'backup', '(none)') AS result;

Returns backup. This query returns the first argument if it isn’t NULL. Otherwise, it returns the second argument if it isn’t NULL. Otherwise, it returns (none).

Related Documentation