HiveBrain v1.2.0
Get Started
← Back to all entries
snippetMinor

How do you handle adding nullable columns to each other in a query?

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
eachyouhandlecolumnsqueryaddingnullablehowother

Problem

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?

Solution

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.

Context

StackExchange Database Administrators Q#1031, answer score: 4

Revisions (0)

No revisions yet.