Joining multiple tables returns NULL value

That is because null on either side of the addition operator will yield a result of null. You can use ISNULL(LiabilityPremium, 0) Example:

ISNULL(l.LiabilityPremium,0) + ISNULL(h.LiabilityPremium,0) as LiabilityPremium

or you can use COALESCE instead of ISNULL.

COALESCE(l.LiabilityPremium,0) + COALESCE(h.LiabilityPremium,0) as LiabilityPremium

Edit

I am not sure if this is coincidence with this small data set or expected but if it is always expected that either @LiabilityPremium.LiabilityPremium or @HiredPremium.LiabilityPremium will always be null then there is no need to perform addition. Instead use COALESCE directly on those 2 columns.

COALESCE(l.LiabilityPremium, h.LiabilityPremium) as LiabilityPremium

Leave a Comment

tech