SQL: COALESCE – Return first non-NULL value from multiple choices

Whilst studying for my MCITP Database Developer certification, I have come across a very useful function 1 that returns the value of the first non-NULL value from multiple choices:

If the MobilePhone field is blank, it will use the HomePhone value instead.

The difference between this function and ISNULL, is that COALESCE can accept multiple values:

COALESCE(field1, field2, …, fieldn)

  1. Please ensure you test any script taken from my website on a test/development machine, before running on a production server.

1 Comment

Add a Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

CJayMead's SQL Server, Endeca, MS Office Help © 2018