Do Not Do the Work Your Database Can Do
Yesterday I had to quickly generate some reports for my general manager. Two of them were no-brainers, just a straight read from a table and dumping out the data in a PDF. The third was a little more complicated, or so I thought.
Basically my database has three main tables: one for basic client information, one for a summary of policy information, and one table holds the actual policy data. In case you could not guess, my primary occupation is in insurance. They needed a report based off of a field from the policy data and that is not exactly a structured table. Each row contains an associated PolicyID, a FieldName, and a Data value. The great part about doing it this way is if I need to add a field to the policy information I just add it to the form with no need to edit the database structure or the CFC that handles reading and writing the data. Painless.
Anyway, to make a long story short, I was trying to come up with a solution in CF that involved querying the policy data table to get all the unique values for the field I needed. Then I was going to loop through that data and build a client and policy query from scratch. I was so focused on a CF-based solution I missed the obvious one, just modifying the client query I used on the other reports to include the field I needed. It only took 5 minutes to get it going instead of hours and a couple hundred lines of code.
I have seen quite a few other blog posts recently stating much the same thing. Next time I suppose I should pay better attention to them.



This is one of my Pet Peeves - and one of the things I annoy my colleagues with most frequently with when reviewing code - its generally easier in the long run to just get the SQL returning the right information - not to mention several orders of magnitude quicker (sometimes thousands of times quicker for the type of scenario you have illustrated when dealing with tall wide data sets)
here's one I caught a while back... http://www.danlance.co.uk/index.cfm/2007/3/20/Neve...