ISNULL (Transact-SQL) is a T-SQL function that replaces a NULL expression with a specified replacement value. It evaluates check_expression and returns replacement_value if it is NULL; otherwise, it returns the expression unchanged.
SELECT ISNULL(NULL, 'N/A') AS Result;
ISNULL replaces a NULL with a supplied replacement. It is supported on SQL Server, Azure SQL Database, Azure SQL Managed Instance, Azure Synapse Analytics, and Analytics Platform System (PDW). Code examples use the AdventureWorks2025 or AdventureWorksDW2025 sample database.
ISNULL T-SQL Syntax Reference
The canonical syntax for the ISNULL function:
ISNULL ( check_expression , replacement_value )
- check_expression – the expression to check for NULL. Can be of any type.
- replacement_value – the value returned if
check_expressionis NULL. Must be implicitly convertible to the type ofcheck_expression.
Tested on SQL Server 2022 with AdventureWorks2025 sample database.
ISNULL Rapid Reference Cheat Sheet
| Action | Statement | Database | Key Parameter | Result |
|---|---|---|---|---|
| Replace NULL with a string | SELECT ISNULL(NULL, 'N/A') AS Result; |
SQL Server / Azure SQL | replacement_value = 'N/A' |
Returns N/A |
| Replace NULL with a default numeric value | SELECT ISNULL(column_name, 0) FROM table; |
SQL Server / Azure SQL | replacement_value = 0 |
Returns 0 for NULLs |
| Use ISNULL inside a WHERE clause | SELECT * FROM Orders WHERE ISNULL(ShipDate, '1900-01-01') > '2023-01-01'; |
SQL Server | Replacement date for NULL | Rows where ship date is after given date or NULL replaced |
| Cross-database equivalent: MySQL IFNULL | SELECT IFNULL(NULL, 'N/A'); |
MySQL / MariaDB | Same logic, different function name | Returns N/A |
| Cross-database equivalent: Oracle NVL | SELECT NVL(NULL, 'N/A') FROM dual; |
Oracle | Same logic, different function name | Returns N/A |
| ANSI-compliant alternative: COALESCE | SELECT COALESCE(NULL, 'N/A'); |
All major SQL databases | Accepts multiple arguments | Returns first non-NULL value |
Advanced Implementation & Parameters
Return Type Determination
The return type of ISNULL follows SQL Server data type precedence rules. If replacement_value has higher precedence than check_expression, the result is implicitly cast to that type, which can cause data loss or conversion errors. For example:
-- check_expression is INT, replacement_value is VARCHAR
SELECT ISNULL(5, 'abc'); -- Returns 5 (INT), 'abc' is never used
If data types are incompatible, SQL Server raises error 245 (Conversion failed). To avoid this, use CAST or CONVERT on the arguments:
SELECT ISNULL(CAST(column AS VARCHAR(20)), 'N/A') FROM table;
Behavior with AVG and Aggregates
ISNULL is often used inside aggregate functions to treat NULLs as zeros, but this changes average semantics. Example:
-- Without ISNULL: AVG ignores NULLs (divisor is count of non-NULL)
SELECT AVG(Salary) AS AvgSalary FROM Employees;
-- With ISNULL: NULLs become 0, divisor includes zeros
SELECT AVG(ISNULL(Salary, 0)) AS AvgSalaryWithZeros FROM Employees;
Using ISNULL inside AVG artificially lowers the average because rows with NULL salary are counted as zero instead of being excluded. This is a common pitfall.
ISNULL vs COALESCE – Performance and Semantic Differences
| Feature | ISNULL | COALESCE |
|---|---|---|
| Number of arguments | Exactly 2 | 2+ (variable) |
| Data type precedence | Uses highest precedence among arguments | Uses highest precedence among all arguments |
| NULL-handling in replacement | If replacement_value itself is NULL, ISNULL returns NULL | Continues to next argument |
| ANSI compliance | SQL Server-specific | ISO/IEC 9075 (SQL:2003) standard |
| Evaluation | Always evaluates both arguments | Short-circuits when first non-NULL found |
Recommendation: Use COALESCE for portability and when handling multiple fallbacks. Use ISNULL only when the database will never be migrated and the two-argument limitation is acceptable.
Error Resolution & Troubleshooting
| Error/Symptom | Root Cause | Remediation Command |
|---|---|---|
| Msg 245, Level 16, State 1: Conversion failed when converting the varchar value ‘abc’ to data type int. | Data type mismatch between check_expression and replacement_value; implicit conversion fails. |
SELECT ISNULL(CAST(column AS VARCHAR(20)), 'abc') FROM table; – explicitly cast both to a common compatible type. |
| Unexpected NULL in result set despite using ISNULL | replacement_value itself is NULL, or check_expression is not NULL but an empty string (”), which ISNULL treats as non-NULL. |
Use COALESCE with a third fallback, or add NULLIF to convert empty strings to NULL: SELECT ISNULL(NULLIF(column,''), 'N/A') FROM table; |
| Incorrect average or sum after using ISNULL inside aggregate | NULLs replaced with 0 affect arithmetic mean/count. | Use AVG(CASE WHEN column IS NOT NULL THEN column ELSE NULL END) or AVG(column) without ISNULL to exclude NULLs. |
| Performance degradation in queries with many ISNULL expressions | ISNULL prevents certain index seeks because the function wraps the column. | Rewrite queries with WHERE column IS NOT NULL or use computed columns/indexed views if possible. |
Common Mistakes
- Using ISNULL as a NULL-check predicate: In SQL Server,
WHERE ISNULL(col, 0) > 10is less efficient thanWHERE col > 10 OR col IS NULL. The former suppresses index usage. - Assuming ISNULL is portable: MySQL uses
IFNULL, Oracle usesNVL, PostgreSQL usesCOALESCE. WritingISNULLin non-SQL Server databases fails. - Ignoring data type precedence:
ISNULL(5.0, 'N/A')fails because ‘N/A’ cannot be cast to float. Use a compatible numeric replacement or cast explicitly.
Production-Grade Implementation
Index and Performance Considerations
- Avoid wrapping indexed columns in
ISNULLin WHERE clauses. This turns a seek into a scan. Instead, rewrite predicates to useOR IS NULL. - For computed columns that need to treat NULLs as a default, use a persisted computed column defined with
ISNULLand then index it. - When using
ISNULLin joins, ensure both sides have proper indexes. The function on the join column disables index usage.
Security and Permissions
ISNULLdoes not require special permissions; it is part of T-SQL expression evaluation. However, if used in views or computed columns, the underlying tables must be accessible.- Be cautious of SQL injection: if replacement_value is built from user input, it can be injected. Always parameterize queries.
- When migrating databases, script all
ISNULLoccurrences and replace withCOALESCEto ensure cross-platform compatibility.
Automation and Monitoring
- Use
sp_helpor querysys.columnsto identify columns that are nullable and often used with ISNULL. Set default constraints instead when possible. - In ETL processes, replace
ISNULLwithCOALESCEfor better readability and portability between source and target platforms. - Monitor execution plans for index scans caused by
ISNULLwrappers. Use theMissing IndexDMV to identify opportunities.
Frequently Asked Questions
What is the difference between ISNULL and COALESCE in T-SQL?
Answer: ISNULL accepts exactly two arguments (expression, replacement); COALESCE accepts multiple and evaluates them in order.
ISNULL is T-SQL-specific, while COALESCE is ANSI standard. ISNULL implicitly converts the replacement value to the type of the expression; COALESCE uses the highest precedence type. For NULL handling with multiple fallback values, use COALESCE. For simple NULL replacement, ISNULL is slightly faster.
When should I use the ISNULL function instead of the IS NULL predicate?
Answer: Use ISNULL to replace NULL with a specific value in output; use IS NULL in WHERE conditions to filter for NULL rows.
-- ISNULL for display replacement
SELECT ISNULL(column, 'DefaultValue') FROM table;
-- IS NULL for filtering
SELECT * FROM table WHERE column IS NULL;
ISNULL is a scalar function returning a value; IS NULL is a logical predicate producing Boolean for filtering.
How do I fix the error ‘ISNULL requires 2 arguments’ in T-SQL?
Answer: Ensure you provide exactly two parameters: the expression to check and the replacement value.
-- Correct: ISNULL(expression, replacement)
SELECT ISNULL(NULL, 0); -- Returns 0
-- Incorrect: fewer or more than 2 arguments
-- ISNULL(NULL) -- Error
-- ISNULL(NULL,0,1) -- Error
If you need multiple fallbacks, use COALESCE. Check parentheses and commas – nested function calls must be closed properly.
Does the ISNULL function work on Azure SQL Database and AWS RDS for SQL Server?
Answer: Yes, ISNULL is fully supported on Microsoft SQL Server, Azure SQL Database, Azure Synapse Analytics, and AWS RDS for SQL Server.
ISNULL is part of the T-SQL language, so any platform running SQL Server engine supports it. For Google Cloud SQL, use the same compatibility. On hosted SQL Server instances (including Amazon RDS), the function behaves identically. No cross-platform differences exist.
What is the fastest way to handle multiple nullable columns with ISNULL in T-SQL?
Answer: Chain nested ISNULL calls or use COALESCE for readability; nesting ISNULL is slightly faster than COALESCE.
-- Fastest: nested ISNULL
SELECT ISNULL(colA, ISNULL(colB, ISNULL(colC, 'Fallback'))) FROM table;
-- Alternative: COALESCE (slower due to multiple evaluations)
SELECT COALESCE(colA, colB, colC, 'Fallback') FROM table;
For maximum speed, use nested ISNULL. For maintainability with many columns, COALESCE is preferred. Avoid CASE expressions when simple NULL replacement suffices.

Command Line Expert & Software Engineer
Welcome! I’m Thomas Heinrich, a software engineer and system administrator with a deep passion for the Command Line Interface (CLI). With years of experience navigating the terminal, building backend architectures, and automating server deployments, I created this space to share practical, real-world terminal knowledge.
Whether you are a beginner taking your first steps in a Linux environment or a seasoned DevOps engineer looking to optimize your deployment scripts, you will find actionable solutions here. My goal is to help you ditch the mouse, speed up your workflow, and harness the full power of the command line.