Sum of money

  • I am having trouble adding two money values. Currently, I'm trying to accomplish the following:

    SELECT (SELECT sum(penaltyAmt) FROM dbo.penalties) -

    (SELECT sum(awardAmt) FROM dbo.awards)

    I've tried them individually and they work fine, coming up with the appropriate totals, but when I do the select, the answer comes up as NULL. Can anyone suggest a way to do this?

    Thanks in advance!

  • I am assuming your columns allow NULLs in which case you have to add COUNT(*) to SUM because all SQL Server aggregate functions ignore NULLs.  Hope this helps.

    Kind regards,

    Gift Peddie

    Kind regards,
    Gift Peddie

  • Tried this on a small table here and it seems to works fine - do you have any other info/ details about your data or server set up?

     

  • You could try SELECT (SELECT ISNULL(sum(penaltyAmt),0)) FROM dbo.penalties) -

    (SELECT ISNULL(sum(awardAmt),0) FROM dbo.awards), or maybe SELECT (SELECT sum(ISNULL(penaltyAmt,0)) FROM dbo.penalties) -

    (SELECT sum(ISNULL(awardAmt,0)) FROM dbo.awards), or a combination of both. I guess that the first one should work well enough. If it doesn't help, please post some sample data where we could reproduce the result.

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply