• Shaarli
  • Tag cloud
  • Daily
  • RSS
  • Login
4492 shaares
Filters

ISNULL vs COALESCE: Not as Interchangeable as They Look

QRCode

ISNULL and COALESCE differ on result type, truncation, nullability, and how often they evaluate their input. When to use each.

The first difference is the result type and length. ISNULL takes the data type of its first argument and forces the whole result into it.[2] COALESCE follows data-type precedence across all its arguments and picks the type with the highest precedence.[3] When the first argument is narrower than the replacement, ISNULL truncates.

And COALESCE is ANSI standard SQL while ISNULL is specific to T-SQL, so COALESCE ports to other database engines and ISNULL does not.

I reach for COALESCE by default, for the standard syntax, the multi-argument fall-through, and the result length that accounts for all its string arguments rather than truncating to the first.

https://www.sqlserverscience.com/t-sql/null-traps-isnull-vs-coalesce/
September 28, 2026 at 11:18:49 AM EDT *
sql mssql
FILLER
Shaarli · The personal, minimalist, super fast, database-free, bookmarking service by the Shaarli community · Documentation
Fold Fold all Expand Expand all Are you sure you want to delete this link? Are you sure you want to delete this tag? The personal, minimalist, super fast, database-free, bookmarking service by the Shaarli community