posted 14 years ago
Unfortunately, yes, it has to be done in a single query, or at least, I need a single result set containing all of that data, as the combined data needs to go into a single record (i.e. one row needs to contain Budget1Amount, Budget2Amount, etc). In addition, this query is highly dynamic, as there can be anywhere from 1 to 5 "columns" where the user can request budget amounts, year amounts, or estimated amounts, and the MonthXCashBasisAmount fields only apply if the user is requesting a year amount, etc. The code to make up this query takes about 175 lines of code because of all the if statements and for loops necessary (and will require more in order to check which database system is in use and do the necessary union/exclusion joins). Right now, though, if I can just figure out how to make this query work in db2, I can figure out how to make the dynamic part work later. Piece-mealing it together would be fine, so long as I can end up with a single result set that contains all the data I need for inserting into the table for the report.