Currently whenever I write a query that is adding columns that can contain nulls I resort to wrapping each field in
coalesce, such as
coalesce(score1,0) + coalesce(score2,0).
Is there a better way to handle this, or is this the standard practice?
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. It's 100% free, no registration required.
Here's how it works:
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
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.