THE WORLD'S LARGEST WEB DEVELOPER SITE

SQL Server COALESCE() Function

❮ SQL Server Functions

Example

Return the first non-null value in a list:

SELECT COALESCE(NULL, NULL, NULL, 'W3Schools.com', NULL, 'Example.com');
Try it Yourself »

Definition and Usage

The COALESCE() function returns the first non-null value in a list.

Syntax

COALESCE(val1, val2, ...., val_n)

Parameter Values

Parameter Description
val1, val2, val_n Required. The values to test

Technical Details

Works in: SQL Server (starting with 2008), Azure SQL Database, Azure SQL Data Warehouse, Parallel Data Warehouse

More Examples

Example

Return the first non-null values in a list:

SELECT COALESCE(NULL, 1, 2, 'W3Schools.com');
Try it Yourself »

❮ SQL Server Functions