Skip to content
Advertisement

Eliminate duplication from a SQL query to avoid returning NULLs from a LEFT/RIGHT JOIN

Have this MS SQL query

When there is no rows matching on the left side of the JOIN want to return 0s instead of NULLs that is why have

Without having to define a scalar function, is there way to remove the repetitive

or a more concise way to return 0’s?

NOTE: Values in Page table (ex. AmountGB) can have nulls that is why the ISNULL(f.AmountGB, 0).

NOTE: Not allowed to change the table definition.

Advertisement

Answer

This would be much simpler as:

I also recommend LEFT JOIN:

User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement