I have a report generator that is having some speed issues. What this does is loops over each category in the db per each category and performs and count on each one. The SQL queries are lightning fast, I even use getrows to get the data out quickly, but I think I should be able to use the loops much better than I do. The String Building is unoptimized I realize but that shouldn't give me as bad performance problems as I'm having. If anyone would be willing to take a look and suggest anything I'm all ears. Most of the problem is how much of this has to be generated dynamically, if I could do something to build the main and subcategories faster it would be fantastic.
Thanks
David
Thanks
David
Code:
from_date = trim(Request.Form("fromdate"))
to_date = trim(Request.Form("todate"))
grp = trim(Request.Form("grp"))
Set main_category_rows = New GetRows
arr_maincat = main_category_rows.GetArray("SELECT maincategory_id, maincategory FROM tracking_maincategory")
strDropDown = "<option value="""">---- Select an option ----</option>"
For j = 0 To UBound(arr_maincat, 2)
maincategory_id = arr_maincat(0, j)
maincategory = arr_maincat(1, j)
strHTML = strHTML & "<td valign=""top""><fieldset><legend><a href="""">" & maincategory & "</a></legend>" & vbCrLf
strHTML = strHTML & "<table height=""212"" style=""font-size: 12px; font-family: verdana;"">"
Set subcategory_rows = New GetRows
arr_subcat = subcategory_rows.GetArray("SELECT category_id, subcategory FROM tracking_category WHERE activated = 1 AND maincategory_id = '" & maincategory_id & "'")
For k = 0 To UBound(arr_subcat, 2)
category_id = arr_subcat(0, k)
category = arr_subcat(1, k)
strDropDown = strDropDown & "<option value=""" & category_id & """>" & maincategory & " - " & category
strHTML = strHTML & "<tr><td valign=""top"">" & category & "</td>"
Set cat_count = New GetRows
strSQL = "SELECT COUNT(category) FROM incident_tracking WHERE category = '" & category_id & "'"
If from_date <> "" and to_date <> "" Then
strSQL = strSQL & " AND submitdate BETWEEN '" & from_date & "' AND '" & to_date & "'"
Else
strSQL = strSQL & " AND submitdate BETWEEN DATE_SUB(curdate(),INTERVAL WEEKDAY(curdate()) DAY) AND DATE_ADD(curdate(),INTERVAL 5-WEEKDAY(curdate()) DAY)"
End If
arr_cat_count = cat_count.GetArray(strSQL)
count = arr_cat_count(0, 0)
If from_date <> "" and to_date <> "" Then
indQuery = "?from_date=" & from_date & "&to_date=" & to_date & "&grp=" & category_id
Else
indQuery = "?grp=" & category_id
End If
strHTML = strHTML & "<td valign=""top"" align=""right"" width=""40""><a href=""TrackingReport_ind.asp" & indQuery & """ >" & count & "</a></td></tr>"
Next
strHTML = strHTML & "</table>"
strHTML = strHTML & "</fieldset></td>"
Next
If from_date <> "" and to_date <> "" Then
If grp <> "" Then
excelQuery = "?from_date=" & from_date & "&to_date=" & to_date & "&grp=" & grp
Else
excelQuery = "?from_date=" & from_date & "&to_date=" & to_date
End If
extendedTitle = " For " & formatDate("%F %j%O", from_date) & " Through " & formatDate("%F %j%O", to_date)
ElseIf grp <> "" Then
excelQuery = "?grp=" & grp
extendedTitle = " For The Current Week"
Else
extendedTitle = " For The Current Week"
End If