Thats some interesting code. What are the chances you could do a re-design on the database? Is this being filled by another application or does it exist purely for this one? I see several places that imply some of the structure of your table and from what I can see you would gain quite a bit of efficiency and simplicity from a minor rewrite.
Right now it looks like you have columns set up for SUPID, Year1, 120 fields for item vs month, and possibly more that you aren't accesssing from this page. This could easily be split into three tables (Score, Month, Item) or even Two( Score, Item) with Month and VarItem being lookup tables. This would not only make your database smaller (instead of storing a whole lot of empty fields, etc) it will decrease transmision time between your database and web server, allow you to increase the efficiency of your script by quite a bit (right now your executing 160 Executes per record found in the database, we could cut that to 0), and allow you to simplify a good deal of your code for later maintainability (like if you get hit by a bus

). With the changes you also wouldn't have to rewrite your code if they suddenly came up with some magic new Item they wanted added, in fact itshould take all of 30 seconds to add it with a better db design. Th code should just adapt without changes.
Ideally I would think you would want a setup like this:
Score
score_id- autonumber or seeded integer
SUPID - text? dunno what this field stands for
Score - number (dunno what kind, probably integer)
aDate - short date
item_id - integer (long)
Item
item_id - autonumber or seeded integer
item_short - text field or varcar, 4 character length
item_long - text field or varchar, 25 character length
objective - text value to cover all types
If there are necesary fields that I haven't included I could add them fairly easily for you, just mention it.
Now to start a display page we could use SUM functions in our SQL statement, group by the month and we could use COUNT to get the counts. This takes some of the burden off our script and reduces the amount of memory we will need for the ASP script. We would also want to order it by the Date field and the Item field to get groups of records with the same item in order by month (ORDER BY item_id, aDate).
So lets throw together some sample code real quick:
Code:
<%
Option Explicit
%>
<!--#Include file="../Includes/openDBconnections1.asp" -->
<!--#Include file="../Includes/format.asp" -->
<!-- All the top html -->
<%
FName = request.querystring("FName")
LName = request.querystring("LName")
YEAR1 = Year(Now())
SQL = "SELECT Score.SUPID, SUM(Score.Score) as ScoreTotal, SUM(Score.Score) as ScoreCount, Month(Score.aDate) as aMonth, Item.item_id, Item.item_short, Item.item_long, Item.objective "
SQL = SQL & "FROM (Score INNER JOIN Item ON Score.item_id = Item.item_id) "
SQL = SQL & "WHERE SUPID = '"& request.querystring("SUPID") &"' "
SQL = SQL & "AND YEAR(aDate) = "& YEAR1 & " "
SQL = SQL & "GROUP BY Score.SUPID, Month(Score.aDate) as aMonth, Item.item_id, Item.item_short, Item.item_long, Item.objective "
SQL = SQL & "ORDER BY Item, Month(aDate)"
objrec.open SQL,objcon,3,3
Dim aMonth, anItem, yearTotal
Dim t_ctr
'--- Output stuff to start the table
Response.Write "<table><tr><th colspan=""5"">Representative Name Here</th>...etc </tr>"
Response.Write "<tr><td>Item</td><td>Objective</td><td>Pretty Color Cell</td>"
For t_ctr = 1 to 12
Response.Write "<td>" & Left(MonthName(t_ctr),3) & "</td>"
Next
Response.Write "</tr>"
'--- Loop to output data
If Not objrec.EOF Then objRec.MoveFirst
Do Until objRec.EOF
'if first row or item dosn't match item from last loop, start a new row
If anItem <> objRec("item_id") Then
'if there is something in anItem, end the previous row by looping through remaining months
If len(anItem) > 0 Then
For t_ctr = aMonth to 12
Response.Write "<td> </td>"
Next
'output the yearly total from the yearTotal variable
Response.Write "<td>" & yearTotal & "</td>"
'end the row
Response.Write "</tr>"
End If
'start a row for the new item
Response.Write "<tr><td>" & objRec("item_long") & "</td><td>" & objRec("objective") & "</td><td>pretty column here</td>"
'reset the month counter
aMonth = 1
End If
'if the month for the current record matches our month counter, display it and add to total
If objRec("aMonth") = aMonth Then
Response.Write "<td>" & objRec("ScoreTotal") & "</td>"
yearTotal = yearTotal + objRec("ScoreTotal") & "</td>"
'increment the recordset
objRec.MoveNext
Else
'otherwise output an empty square
Response.Write "<td> </td>"
End If
'increment month
aMonth = aMonth + 1
Loop
'--- output more pretty html to end the table and page
Response.Write "</table></body></html>"
%>
One thing this doesn't cover is the percentages for a couple of your fields. My advice on that would be to add a field to the Item table called ItemType and have a way to define sum vs percentage. The in your code add a second year variable called yearTotalCount. Set it to 0 where yearTotal is set to 0, then replace the current record output if statement with three cases instead of just two. The first case is were the months are equivalent and the type is sum, the second is months equivalent and percentage, the third is the blank cell. Unfortunatly I can't show an example for this because I don't know how your obtaining your percentage. The only other change would be tat where your outputting the yearTotal you would first check if yearTotalCount > 0, if so assume you want a percentage and calculate the years percentage, otherwise output just the yearTotal.
There are a couple fields in my select statement that aren't being used and I also did not output links. The links can be built pretty much the same by including the item_id and aMonth values. You could then output all inputs for that item and month combination as well as a blank entry so that they could edit existing entries forthat month or add another. It ends up a little more complicated but you also have finer control over the data that way.
The only other factor mising here is the pretty sction headings. My advice on that matter is to create a section table with section_id and section_text. Add the section id to the Item table, alter the SQl statement to inner join ith the section table on section_id's, add it as the first field in the ORDER BY, then in the item change section of the main loop after you end a row see if the section has changed (keep it in a variable like anItem), if it has changed output a pretty row with the section name.
I know this seems like a lot of work on something you have almost completed, but if nothing else relies on your current database design I would at least consider it. The efficiency, maintainability, and useability will all increase dramatically with this redesign. If you have any questions, feel free to ask, and even if this dosn't help during your current proect hopefully it will help in future projects,
-T
01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website: