rduncan10
8th December 2008, 19:32
I was wondering if anyone has a better way to get totals of the tfgld amount fields where all the numbers are positive.
For example, the following does not work:
SELECT tfgld106.odoc, SUM(tfgld106.amth)
FROM tfgld106
WHERE ...
GROUP BY tfgld106.odoc
...
tfgld106.amth is always positive, whether it is a debit or credit. I mean, I know it can be negative, but a credit of $10 and a debit of $10 are both expressed as 10.0000.
Instead I have to use something like the following:
temp.amnt = 0
SELECT tfgld106.odoc, tfgld106.dbcr, SUM(tfgld106.amth)
FROM tfgld106
WHERE ...
GROUP BY tfgld106.odoc, tfgld106.dbcr
SELECTDO
If tfgld106.dbcr = tfgld.dbcr.credit
temp.amnt = temp.amnt - tfgld106.amth
else
temp.amnt = temp.amnt + tfgld106.amth
endif
ENDSELECTThis always seems kind of clumsy to me and usually results in a lot more code and nested queries.
Thanks,
Rob
For example, the following does not work:
SELECT tfgld106.odoc, SUM(tfgld106.amth)
FROM tfgld106
WHERE ...
GROUP BY tfgld106.odoc
...
tfgld106.amth is always positive, whether it is a debit or credit. I mean, I know it can be negative, but a credit of $10 and a debit of $10 are both expressed as 10.0000.
Instead I have to use something like the following:
temp.amnt = 0
SELECT tfgld106.odoc, tfgld106.dbcr, SUM(tfgld106.amth)
FROM tfgld106
WHERE ...
GROUP BY tfgld106.odoc, tfgld106.dbcr
SELECTDO
If tfgld106.dbcr = tfgld.dbcr.credit
temp.amnt = temp.amnt - tfgld106.amth
else
temp.amnt = temp.amnt + tfgld106.amth
endif
ENDSELECTThis always seems kind of clumsy to me and usually results in a lot more code and nested queries.
Thanks,
Rob