T-SQL reference › COALESCE
COALESCE in SQL Server
COALESCE returns the first argument that is not NULL. You can pass three or four. ISNULL only takes two. See also <a href="/tsql/isnull">ISNULL</a>.
Something we can contact
SELECT customer_id, first_name,
COALESCE(NULLIF(LTRIM(RTRIM(phone)), ''), email, 'No contact') AS contact
FROM Customers;
NULLIF turns a blank phone into NULL so COALESCE can skip it and try email.
Try it on Harbour & Co
Becky Ashworth (Support) needs this now: “Support is phoning customers. Blank phone numbers confuse the team. Can it say No phone instead?” Write the query, run it, send the results. Free.
Take the ticket →Learn it on a real ticket
Monday is free on WorkSQL. A colleague’s ticket lands, you write the T-SQL, we mark it. No videos. Five minutes.
Clock in free See Monday’s tickets