questioners fld list doesn't match group by list
Missy Medlin, July 05, 2018 - 6:09 pm UTC
I've done my share of DIY pivots in my day, that's for sure. But just commenting here that the original SQLs field list and group-by list don't match. That's a bug right there in whatever source code this is.
SUBSTR(a.accode, 1, 6) || '000000' saccode, -- '0000' saccode, -- changed to 6 zeros
July 06, 2018 - 9:21 am UTC
Yes, good catch.
trying out original code
Missy Medlin, July 05, 2018 - 8:08 pm UTC
It looks like they are saying "a negative debit is really a credit, and a negative credit is really a debit" - so that the totals columns for Credit and Debit are always displayed positive. I think...
-- debit positive total of -2
insert into slbal values ('DEBIT_POS_TOTAL','ABB','ACCXCD','D',3);
insert into slbal values ('DEBIT_POS_TOTAL','ABB','ACCXCD','D',-1);
-- debit negative total of -2
insert into slbal values ('DEBIT_NEG_TOTAL','ABB','ACCXCD','D',-3);
insert into slbal values ('DEBIT_NEG_TOTAL','ABB','ACCXCD','D',1);
-- credit positive total of 2
insert into slbal values ('CREDIT_POS_TOTAL','ABB','ACCXCD','C',3);
insert into slbal values ('CREDIT_POS_TOTAL','ABB','ACCXCD','C',-1);
-- credit negative total
insert into slbal values ('CREDIT_NEG_TOTAL','ABB','ACCXCD','C',-3);
insert into slbal values ('CREDIT_NEG_TOTAL','ABB','ACCXCD','C',1);
commit;
July 06, 2018 - 9:22 am UTC
Could be... we'd need to see some sample data from the OP!
Chuck Jolley, July 11, 2018 - 1:52 am UTC
Some financial systems run on journals that have 'C' and 'D' plus an amount.
Others use separate credit and debit columns.
This code is for transferring data from the first to the second.
Getting rid of the negative amounts may, or may not, be actually necessary.
Anyway, that's definitely what this code is for.
Baizeed, August 01, 2018 - 5:04 pm UTC