jenlion
IS-IT--Management
- Nov 13, 2001
- 215
I have base tables that look like this:
In table tglAcctHist, beginningbal is only given for fiscal period one in each fiscal year. For subsequent periods it is calculated based on activity (credits-debits) after that beginning balance in period 1.
in table tglAcctHistAcctRef, I have activity for "sub-accounts" of the main account. If an account in table tglAcctHist had total activty (credits-debits) of, say, 100.00, then the tglAcctHistAcctRef might show that $20 went to reference 2 and $50 went to reference 3. (the remaining $30 was here not assigned a reference code).
Here's what I need to do:
I need to create a report that displays, in one row, the following:
I also need to make sure that every possible account, reference, and fiscalperiod show up, regardless of activity.
My problem is speed. I've created a couple of data views: some with cross joins to get every possible account and fiscal period combo, some to do the "end balance" calculation at the 'base account' level (subtracting activity for that account at reference codes, etc.
The closest I have been able to get to the end goal is a view that gives me this:
That's great, but I actually need to do a sort of pivot that groups by glacctkey, acctrefkey, fiscyear, and then lists the endbal for each fiscper. Not a sum (though it is actually a crazy sum of credits and debits of previous periods, and I worked through this in my little views that feed into this main view).
I can't find the proper command that will do this. I'm finding some about summarizing and grouping by into a cube, but I don't need to sum anything.
I know it can be done -- Crystal does a Crosstab report relatively quickly that lays it out exactly the right way, except it insists on totalling up the results. Totals don't make any sense here, so the "with cube" option doesn't seem to do it.
I tried joining the view back to itself for each period, but that wound up being too clunky -- takes too long to run.
The current business requirement is to have this output to crystal (and then save it easily to csv). But I prefer to get this exactly as desired in sql so it can eventually be run directly, easily to csv.
The db is 6.5-compat so no ctes, nothing new or fancy. I know there's got TO be a way to do this.... but what is it?
Code:
table tglAcctHist
glacctkey fiscyear fiscper beginningbal creditamt debitamt
Code:
table tglAcctHistAcctRef
glacctkey acctrefkey fiscyear fiscper creditamt debitamt
In table tglAcctHist, beginningbal is only given for fiscal period one in each fiscal year. For subsequent periods it is calculated based on activity (credits-debits) after that beginning balance in period 1.
in table tglAcctHistAcctRef, I have activity for "sub-accounts" of the main account. If an account in table tglAcctHist had total activty (credits-debits) of, say, 100.00, then the tglAcctHistAcctRef might show that $20 went to reference 2 and $50 went to reference 3. (the remaining $30 was here not assigned a reference code).
Here's what I need to do:
I need to create a report that displays, in one row, the following:
Code:
glacctkey acctrefkey fiscyear EndBalPeriod1 EndBalPeriod2 EndBalPeriod3 EndBalPeriod[4...12]
My problem is speed. I've created a couple of data views: some with cross joins to get every possible account and fiscal period combo, some to do the "end balance" calculation at the 'base account' level (subtracting activity for that account at reference codes, etc.
The closest I have been able to get to the end goal is a view that gives me this:
Code:
glacctkey acctrefkey fiscyear fiscper endbal
That's great, but I actually need to do a sort of pivot that groups by glacctkey, acctrefkey, fiscyear, and then lists the endbal for each fiscper. Not a sum (though it is actually a crazy sum of credits and debits of previous periods, and I worked through this in my little views that feed into this main view).
I can't find the proper command that will do this. I'm finding some about summarizing and grouping by into a cube, but I don't need to sum anything.
I know it can be done -- Crystal does a Crosstab report relatively quickly that lays it out exactly the right way, except it insists on totalling up the results. Totals don't make any sense here, so the "with cube" option doesn't seem to do it.
I tried joining the view back to itself for each period, but that wound up being too clunky -- takes too long to run.
The current business requirement is to have this output to crystal (and then save it easily to csv). But I prefer to get this exactly as desired in sql so it can eventually be run directly, easily to csv.
The db is 6.5-compat so no ctes, nothing new or fancy. I know there's got TO be a way to do this.... but what is it?