question

apple avatar image
apple asked

Coalesce with sum

I want the sum to be zero instead of null in a case statement Case when transactiontypecode = 'ABS' then coalesce(sum(Amt),0) end as ABS , Is there a way around this? Thanks a lot
sqlaggregatesnull
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
Tom Staab avatar image
Tom Staab answered
Just change the order of operations. Instead of CASE WHEN transactiontypecode = 'ABS' THEN COALESCE(SUM(Amt),0) END AS ABS do SUM(CASE WHEN transactiontypecode = 'ABS' THEN Amt ELSE 0 END) AS ABS
1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

apple avatar image apple commented ·
Thanks a lot It worked Appreciate greatly
0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.