Struggling to display output of RS as a horizontal table.
I’ve a RS based on following SQL
SQL = "SELECT INTRAY.TEAM, Count(INTRAY.DOC_GUID) AS NumDocs " & _
"FROM INTRAY INNER JOIN DOCUMENT ON INTRAY.DOC_GUID = DOCUMENT.GUID " & _
"WHERE DOCUMENT.DOC_TYPE = 'PNEW' " & _
"AND DOCUMENT.DATE_RECEIVED > '"& Year(FromDate) &"-"& Month(FromDate) &"-"& Day(FromDate) &"' " & _
"GROUP BY INTRAY.TEAM, INTRAY.MAIL_STATUS, INTRAY.FILE_SYSTEM " & _
"HAVING INTRAY.MAIL_STATUS = 'NT' AND INTRAY.FILE_SYSTEM ='B' " & _
"ORDER BY INTRAY.TEAM ;"
I display results in a normal table, as below
<table border=1>
<tr>
<th>Team</th>
<th>Records</th>
</tr>
<%Do While Not RS.EOF %>
<tr>
<td><%=RS("TEAM")%></td>
<td><%=RS("NumDocs")%></td>
</tr>
<% RS.MoveNext
Loop%>
</table>
The resutls display normally in a vertial table. 10 records are returned, sorted by Team. OPS1, OPS10, OPS2 etc.
Note that 10 comes after 1 due to alpha sorting, don’t know how to amend this.
There are only ever 10 teams that could be in the output, but sometimes not all will have a result, so the table could only return say, 2 or 3 teams.
I want to create a table which has hard coded column headings for each possible team (1 – 10), and then the next row being the output values for NumDocs
Team 1 10 2 3 4 5 6 7 8 9
Results 8 4 7 17 4 87 20 19 1 7
So, I then close the recordset, and re-open it;
<%RS.Close%>
<br>
<%
RS.cursortype=adOpenKeyset
RS.Open SQL, IConn, 3, 3
RS.MoveFirst
%>
And write the table;
<table border=1>
<th>Report</th>
<th>OPS1</th>
<th>OPS10</th>
<th>OPS2</th>
<th>OPS3</th>
<th>OPS4</th>
<th>OPS5</th>
<th>OPS6</th>
<th>OPS7</th>
<th>OPS8</th>
<th>OPS9</th>
<tr>
<td>Untouched New Records (total)</td>
<td>
<%If RS("Team") = "OPS1" Then %>
<% Response.Write(RS("NumDocs"))
Else Response.Write("Not OPS1")
RS.MoveNext
End If %>
</td>
<td>
<%If RS("Team") = "OPS10" Then %>
<% Response.Write(RS("NumDocs"))
Else Response.Write("Not OPS1")
RS.MoveNext
End If %>
</td>
<td>
<%If RS("Team") = "OPS2" Then %>
<% Response.Write(RS("NumDocs"))
Else Response.Write("Not OPS2")
RS.MoveNext
End If %>
</td>
<td>
<%If RS("Team") = "OPS3" Then %>
<% Response.Write(RS("NumDocs"))
Else Response.Write("Not OPS3")
RS.MoveNext
End If %>
</td>
<td>
<%If RS("Team") = "OPS4" Then %>
<% Response.Write(RS("NumDocs"))
Else Response.Write("Not OPS4")
RS.MoveNext
End If %>
</td>
<td>
<%If RS("Team") = "OPS5" Then %>
<% Response.Write(RS("NumDocs"))
Else Response.Write("Not OPS5")
RS.MoveNext
End If %>
</td>
<td>
<%If RS("Team") = "OPS6" Then %>
<% Response.Write(RS("NumDocs"))
Else Response.Write("Not OPS6")
RS.MoveNext
End If %>
</td>
<td>
<%If RS("Team") = "OPS7 " Then %>
<% Response.Write(RS("NumDocs"))
Else Response.Write("Not OPS7")
RS.MoveNext
End If %>
</td>
<td>
<%If RS("Team") = "OPS8" Then %>
<% Response.Write(RS("NumDocs"))
Else Response.Write("Not OPS8")
RS.MoveNext
End If %>
</td>
<td>
<%If RS("Team") = "OPS9" Then %>
<% Response.Write(RS("NumDocs"))
Else Response.Write("Not OPS9")
RS.MoveNext
End If %>
</td>
</tr>
</table>
It won’t work, all I get it ‘Not OPSx” in the output.
The If Test is not working.
If I amend each cell to
<% Response.Write(RS("NumDocs"))
RS.MoveNext %>
Then it will write the value, but I need to test for the value of TEAM in that row in the RS, and if I amend this to
<% If RS("Team") = "OPS1" Then
Response.Write(RS("NumDocs"))
End If
RS.MoveNext %>
It won’t work and writes nothing.
Any ideas why mty IF is not working? When I write the values of TEAM, they appear to be OK and don’t have trailing spaces. The SQL Server won’t accept a TRIM function
SQL Server may not accept
TRIM, but it should acceptRTRIMandLTRIM, such as:If you don’t want to trim in your SQL statement (which I suggest you do), you can always try trimming your
IFstatements like this:If you do
<% Response.Write "!" & RS("Team") & "!") %>of your data right now, I suspect you’ll see something like: