COALESCE
Description
Sample Source Pattern
Syntax
COALESCE ( expression [ ,...n ] ) COALESCE( <expr1> , <expr2> [ , ... , <exprN> ] )Examples
SELECT TOP 10 StartDate,
COALESCE(EndDate,'2000-01-01') AS FIRST_NOT_NULL
FROM HumanResources.EmployeeDepartmentHistoryStartDate |FIRST_NOT_NULL|
----------+--------------+
2009-01-14| 2000-01-01|
2008-01-31| 2000-01-01|
2007-11-11| 2000-01-01|
2007-12-05| 2010-05-30|
2010-05-31| 2000-01-01|
2008-01-06| 2000-01-01|
2008-01-24| 2000-01-01|
2009-02-08| 2000-01-01|
2008-12-29| 2000-01-01|
2009-01-16| 2000-01-01|SELECT TOP 10 StartDate,
COALESCE(EndDate,'2000-01-01') AS FIRST_NOT_NULL
FROM HumanResources.EmployeeDepartmentHistory;StartDate |FIRST_NOT_NULL|
----------+--------------+
2009-01-14| 2000-01-01|
2008-01-31| 2000-01-01|
2007-11-11| 2000-01-01|
2007-12-05| 2010-05-30|
2010-05-31| 2000-01-01|
2008-01-06| 2000-01-01|
2008-01-24| 2000-01-01|
2009-02-08| 2000-01-01|
2008-12-29| 2000-01-01|
2009-01-16| 2000-01-01|Last updated
Was this helpful?