Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Currently whenever I write a query that is adding columns that can contain nulls I resort to wrapping each field in isnull or coalesce, such as coalesce(score1,0) + coalesce(score2,0). Is there a better way to handle this, or is this the standard practice?

share|improve this question
Can you elaborate? Are these insert / update statements? Are you adding a nullable column to a table, and want a default for existing records or new records? – Eric Humphrey - lotsahelp Feb 2 '11 at 20:13
@Eric Humphrey: Edited the question for clarity. The question was meant for querying columns that can contain nulls, and wanting to add some of them together. – goric Feb 2 '11 at 20:24
up vote 8 down vote accepted

That's pretty much what you have to do. Since NULL + anything else is NULL, you have to wrap each column in its own isnull(), coalesce() or CASE.

share|improve this answer

Oracle provides NVL() for this scenario, ISNULL() is the equivalent in MS SQL Server. You could disguise all this in a VIEW to make your code clearer.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.