Subject Re: [firebird-support] Best table structure for Debit/Credit
Author Matthias Hanft
I wrote:

> How can I put this into a valid FB SQL statement?

Meanwhile, I remembered that there is a table "TRANSTYPES" like this:

TRANSTYPE,FACTOR
C 1
D -1
X 0
[and so on]

from where I can get the information if a certain transaction is
credit or debit (or none).

Using that table, I have now a functionning SQL statement like this:

select
sum(
case currency
when 0 then cast(amount/1.95583 as numeric(9,2))
when 1 then amount
else NULL
end
*
factor
)
as balance
from transactiontable
left join transtypes on transactiontable.transtype=transtypes.transtype
where custno=?

Does this go any better?

(Nevertheless, I still wonder if I can work with "intermediate" CASE
results as asked in my last message.)

Matthias