I need some best practices advice. I'm not sure if there is a better way to do what I'm trying to accomplish. The execution time is very high which is why I'm looking for alternatives. I welcome any tips to help reduce this execution time. Hopefully, I can explain this clearly because I'm not seeing it clearly. I'm going to just use one form field for this example, however, there are about 10 search field options.
Multiple items (checkboxes) can be selected for one field. I am going to use CODES for my example.
The cfquery on the results page uses a view that has been created in the database. This view joins a primary table (company) to several other tables (i.e., codes) that possibly have many records for that one company. Within the cfquery, I use IN for the joined tables just to see if that company has any of those records. It appears to be working and not taking too long. In order to output the results, a distinct company is being used because multiple rows could be returned for one company, and I only want to output each company one time.
Then, I want to output the company information. I also want to output the multiple codes for returned for each company. So, I have to do a little query within the main query output to get those records. Because there are so many search field options, this is where I believe the execution time is slowing down because is has to loop very every company returned (800+) and multiple search fields means different queries. Below is a sample piece of the code.
I am thankful and open to any ideas. Sincerely.
<cfquery datasource="xxx" name="Company">
Select distinct company
cfif isdefined("code") and code neq ''> and code IN (<cfqueryparam value="#form.code#" list="yes">)</cfif>
<CFQUERY DATASOURCE="xxx" NAME="getCodes">
WHERE code IN (<cfqueryparam value="#form.code#">)