COALESCE
NULL fallback chain (rewritten as CASE)
What changes
- Input
- two or more expressions
- Output or change
- first non-NULL value
- Return type
- Returns the data type of expression with the highest data type precedence. If all expressions are non-nullable, the result is typed as non-nullable.
Syntax at a glance
COALESCE ( expression [ , ...n ] )
Work example
Choose the first available value from several nullable expressions.
Set an explicit common type when arguments differ and avoid volatile subqueries as repeated arguments.
Check your work COALESCE follows CASE type precedence and an argument expression can be evaluated more than once.
Practice SQL
Open in SQL FlowSELECT COALESCE(CAST(NULL AS varchar(12)), 'unknown') AS label;
Open Microsoft Learn for full syntax, permissions, and details for your version.