SQL Server Interview Question #58
What is the difference between ISNULL() and COALESCE()?
SELECT, Filtering, Sorting & Built-in Functions Mid-Level Intermediate
Detailed Explanation
Both can provide fallback values for NULL, but they are not identical. ISNULL is a SQL Server-specific function with two arguments. COALESCE is a standard SQL expression and can accept multiple arguments, returning the first non-NULL expression.
Their data-type precedence, nullability metadata, and evaluation semantics can differ. Therefore, they should not be considered perfectly interchangeable merely because simple examples return the same value.
Code Example
SELECT COALESCE(MobilePhone, HomePhone, OfficePhone, N'No phone')
FROM dbo.Customers;
SELECT ISNULL(Nickname, FullName)
FROM dbo.Customers;