There is a task that is currently written in FileMaker and it does everything it needs to do…but not quickly enough, so we’re contemplating porting that process to some flavor of SQL (let’s say MySQL for now) to bypass FileMaker’s speed limitations.
The “over my head” part comes from the fact that it is a nested looping script and I neither know how to write incrementing loops in SQL nor how to write some kind of static nonlooping query that would do the same thing.
There is a table called Bus. The looping script goes through each record of it. A start date and an end date is specified for a report.
… For each record in Bus a loop is started at Start Date, does stuff, goes to next date, and so on until End Date.
… For each Date, a list of Client record IDs is obtained, of Clients who were attached to that Bus that were active on that Date; and a loop is started at midnight and increments one hour at a time until 11 PM.
… For each Hour, for that Bus, on that Date, the clients on the client list is looped through and a reading taken, and then this loop increments to the next hour.
Within that list of Clients, parameters from each indiv client are obtained and then
a quantitative value is read in from a Readings table, the specific Readings record being identified by a combination of field values some of which come from the Bus record, some from the Date or from parameters in yet other tables that are specific to the Day of Week of that Date, some from the specific Hour, and some from the specific Client under consideration. As this inner loop runs, that reading is tossed into an equation to yield a result which is added to the result of all prior clients within this same hour / same date / same Bus, and the aggregate total for that Bus/Date/Hour is written out as a cell value in the report. The resulting value is “per the hour” and aggregates all the clients’s readings for that hour.
In FileMaker these loops are written as a script with this kind of syntax:
Loop
…Exit Loop if [specify exit condition]
…do stuff
… Loop
… Exit Loop If [specify exit condition]
… do stuff
… increment something to approach exit condition
… End Loop
… increment something to approach exit condition
End Loop
How would one do such a thing in a SQL environment? Would it normally be done outside of the SQL language environment in a front-end environment and, if so, is php the best place to write the loop syntax, or should I be investigating things such as Brio or Crystal Reports for this kind of task? (I assume Brio and Crystal are still around due to some things you can do better in them than in php?)