August 25, 2005 at 3:55 pm
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!
August 25, 2005 at 4:27 pm
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
August 26, 2005 at 1:23 am
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?
August 26, 2005 at 2:56 am
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