Given the following customer's transactions (invoices & credit memos)
DocType OrigDocAmt CustomerID
------- -------------- -----------
CRM 100 10278
CRM 150 10278
CRM 75 10278
INV 200 10278
I need to get the total amount. Taking into consideration that INV should be negative
select sum(case when DocType = 'INV' then -OrigDocAmt else OrigDocAmt end) TheTotal from
ARRegister where CustomerID=10278
TheTotal
---------------------------------------
125
How do I write an Aggregated BQL to do that ? I can't just call Sum<> as it will give me 525.
Thanks in advance !