Home All Groups Group Topic Archive Search About

adding three fields together

Author
7 Jan 2007 6:54 PM
childofthe1980s
Hello:

The following is a formula that I created in SQL to add the payment/credit
memo amount, discount taken amount, and the write-off amount of each invoice
as a column that I call "TOTAL CREDITS":

COALESCE(RM20201.APPTOAMT, '0') + COALESCE(RM20201.DISTKNAM, '0') +
COALESCE(RM20201.WROFAMNT, '0') AS 'TOTAL CREDITS'

I really need all three of these items to add together as one lump-sum.  For
instance, if invoice #200 has a $300.00 payment, a $5.00 discount taken, and
a $25.00 write-off, the TOTAL CREDITS column needs to display as $330.00. 
This is the total of all three fields. 

But, what SQL is doing is displaying each of these three items separately in
the column.  In other words, instead of showing invoice #200 as one record
with a lump-sum of TOTAL CREDITS as $330.00, SQL is showing invoice #200 as
three records with the $300.00 payment as one record, the $5.00 discount
taken as one record, and the $25.00 write-off as one record.

How do you compute such a lump-sum amount in SQL?  If anyone can tell me how
to do this, I would greatly appreciate it!  This would solve all of my
problems with this small project that I am working on.

By the way, the reason I used the COALESCE argument is so a field that does
not contain one of these three items would show as 0.00000 rather than as
NULL.

Thanks!

childofthe1980s

AddThis Social Bookmark Button