First we need to give our client a way to manage these levels or "tiers" as we will call them. A simple interface will do:
Here is an example report, This was run before we added one more level. FYI: we can also have static columns such as the first one that appears on the image below.
There are two parts for this solution. The first one is to create a dynamic query which will populate a table from which we can run our query. The second part, is a stored procedure to feed our report.
- Procedure to create our view and update our example table
At this point, we will need to delete the columns from our display fields table if they were deleted. We can just check the current dynamic fields from our EXAMPLE_TABLE against our display fields table and delete them similarly to what we did for adding columns(ALTER TABLE).
Finally, we can run our query and populate our table with our recently dynamically created query.
There is a job which runs every night which executes this procedure and thus refreshes the table. So you can imagine the happiness of our user tomorrow when he gets a new copy of the report and magically the columns he added recently shows up in there. No request, no test or deployment.
I will show the report in Part 2 next.