How to Use COALESCE in SQL Server
Last updated July 25, 2026 · By the SaturnSQL team
COALESCE returns the first non-NULL value from its argument list, e.g. COALESCE(mobile_phone, work_phone, 'none'). It is standard SQL and takes any number of arguments. ISNULL is similar but SQL Server-only, limited to two arguments, and types the result differently.
SELECT id,
COALESCE(mobile_phone, work_phone, 'no phone') AS contact_phone
FROM customers;COALESCE vs ISNULL
ISNULL(a, b) takes exactly two arguments and returns the data type of the first, silently truncating the fallback when it is longer. COALESCE uses data type precedence across all arguments and is portable to other databases. ISNULL is marginally faster, and its result counts as NOT NULL when the first argument is a NOT NULL column, which matters in computed columns and SELECT INTO.
-- ISNULL truncates to the type of the first argument
DECLARE @code CHAR(2) = NULL;
SELECT ISNULL(@code, 'unknown'); -- 'un'
SELECT COALESCE(@code, 'unknown'); -- 'unknown'Defaulting aggregates
COALESCE expands to a CASE expression internally, so a subquery argument can be evaluated twice; ISNULL evaluates it once.
SELECT c.id,
COALESCE(SUM(o.amount), 0) AS lifetime_value
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.id
GROUP BY c.id;Run this in SaturnSQL
SaturnSQL is a browser-based SQL editor for teams: shared query library, schema-aware autocomplete, and scheduled exports to Google Sheets and Slack.
Try it free