Hi Everyone,
I'm trying to write a script that will generate a rather large and 'nested' report from my database. I haven't gotten very far yet- I'd like to know if what I'm attempting is feasible, and if anyone has suggestions for the route to take.
My database includes records of products ordered, when, who by, and many other details. The report I need to generate will contain many pages, with smaller reports nested amongst others.
For example, the first page would be a list of the companies which have placed orders in a time period, and the total cost of the products they ordered. Following this would be another page for each company, each breaking down the departments which have ordered items, and the total cost incurred by each. For every department, there would then be another page detailing the Staff members who have placed orders, and their individual totals. And finally for each individual there would be a report listing the codes of products they ordered and the cost total for each of those.
Each of the individual pages is possible to make using a sub-summary report and a find/ sort, but I'm not sure how to script it all together. I was thinking that it may be possible to achieve this using nested loops. Do you think this would work?
Something like:
1. Count the number of Companies which ordered products in the the specified time period.
1. Generate the report with the list of Companies.
2. Count the number of departments in each company which ordered something in the specified time period.
3. Loop through the different companies, for each, Count the number of Departments which ordered products in the the specified time period. Then produce a report with the list of departments.
4. Inside that loop, loop through the different departments, Count the number of Staff members which ordered products in the the specified time period. Then produce a report with the list of Staff.
5. Inside that loop, loop through each staff member producing a report with the list of products.
I hope you understand what I mean. My first stumbling block is the 'counting' parts- to get the number of unique values in a field for a found set. I understand that this may be possible using a self-join relationship, and am working on it at the moment.
Any and all suggestions would be welcome- is this going to work?
Many thanks!
-Sarah