SQL Interview: 95 Are ISNULL and COALESCE the same for two parameters?
This is a post in the SQL Interview series. These aren’t trick or gotcha questions, they’re just questions designed to scope out a candidate’s knowledge around SQL Server and Azure SQL Database.
Section: Development Level: Medium
Question:
If you have two values where you want to return the first if it’s not NULL, and otherwise return the second, is there any difference at all between using the ISNULL and COALESCE functions?
If so, what would be different?
Answer:
ISNULL and COALESCE derive the return data type differently.
ISNULL:
ISNULL returns the same data type as its first parameter. If a literal NULL is provided as the expression to check, it returns the data type of the replacement_value.
However, if a literal NULL is provided as the check expression and no replacement_value is given, it returns an int.
COALESCE:
COALESCE follows the rules for CASE expressions in determining the return data type. It returns the data type of the expression with the highest data type precedence among all the arguments provided. This means COALESCE can dynamically determine the return type based on the data types of all its arguments, ensuring data integrity across potentially mixed types.
2025-12-09