The following code is supposed to get employees from and employee table and sort them by department like so:
NO DEPARTMENT DEFINED:
fred jones
suzy smith
john doe
SALES:
john johnson
bobby brown
sid vicious
MARKETING
Joe joes
etc.
etc.
However there is a problem with the NO DEPARTMENT DEFINED part of the code. If, in the databse, the departmentID field is blank (isnull function), I want it to group under a single heading called NO DEPARTMENT DEFINED. But it is contiually coming out as:
NO DEPARTMENT DEFINED:
fred jones
NO DEPARTMENT DEFINED:
suzy smith
NO DEPARTMENT DEFINED:
john doe
SALES:
john johnson
bobby brown
sid vicious
MARKETING
Joe joes
etc.
etc.
Maybe I've been looking at this code for too long and have lost the ability to see what must be a fairly simple error in my loop. Can someone help me? Case 2 in the code below is where I believe the problem begins.
Do While rsEmployees.EOF = False
Select Case Session("GroupBy"
Case 0:
Case 1:
If LocationID <> rsEmployees("LocationID" Then
Response.Write (" <TR>"
Response.Write (" <TD></TD>"
Response.Write (" <TD valign=top><font size=-1>"
Response.Write (" "
Response.Write (" </TD>"
Response.Write (" <TD></TD>"
Response.Write (" </TR>"
Response.Write (" <TR>"
Response.Write (" <TD></TD>"
Response.Write (" <TD colspan=2 valign=top><font face=""Arial, Helvetica, sans-serif"" size=2><B>"
Response.Write ( rsEmployees("Branch" & "<BR> " & rsEmployees("City" & ", " & rsEmployees("State")
Response.Write (" </B></TD>"
Response.Write (" <TD></TD>"
Response.Write (" </TR>"
End If
LocationID = rsEmployees("LocationID"
Case 2:
If DepartmentID <> rsEmployees("DepartmentID" Then
Response.Write (" <TR>"
Response.Write (" <TD></TD>"
Response.Write (" <TD valign=top><font size=-1>"
Response.Write (" "
Response.Write (" </TD>"
Response.Write (" <TD></TD>"
Response.Write (" </TR>"
Response.Write (" <TR>"
Response.Write (" <TD></TD>"
Response.Write (" <TD colspan=2 valign=top><font face=""Arial, Helvetica, sans-serif"" size=2><B>"
Response.Write ( rsEmployees("Department")
Response.Write (" </B></TD>"
Response.Write (" <TD></TD>"
Response.Write (" </TR>"
else
End if
'Else
If isnull(rsEmployees("DepartmentID") Then
'DepartmentID="No Department Defined"
Response.Write (" <TR>"
Response.Write (" <TD></TD>"
Response.Write (" <TD valign=top><font size=-1>"
Response.Write (" "
Response.Write (" </TD>"
Response.Write (" <TD></TD>"
Response.Write (" </TR>"
Response.Write (" <TR>"
Response.Write (" <TD></TD>"
Response.Write (" <TD colspan=2 valign=top><font face=""Arial, Helvetica, sans-serif"" size=2><B>"
Response.Write ( "No Department Defined"
Response.Write (" </B></TD>"
Response.Write (" <TD></TD>"
Response.Write (" </TR>"
' End If
' If rsEmployees("DepartmentID"="" then
' DepartmentID = rsEmployees("DepartmentID"
else
departmentID=rsEmployees("DepartmentID"
end if
End Select
Response.Write (" <TR>"
Response.Write (" <TD></TD>"
Response.Write (" <TD valign=top><font face=""Arial, Helvetica, sans-serif"" size=2>"
Response.Write (" <a href=employee.asp?r=" & Rand() & "&EmployeeID=" & rsEmployees("EmployeeID" & "&command=Edit>" & rsEmployees("Fullname" & "</a>"
Response.Write (" </TD>"
Response.Write (" <TD><font face=""Arial, Helvetica, sans-serif"" size=2>"
Response.Write ( rsEmployees("Priority")
Response.Write (" </TD>"
Response.Write (" <TD></TD>"
Response.Write (" </TR>"
rsEmployees.MoveNext
Loop
Response.Write ("</TABLE>"
Response.Write ("</tr></td></table>"
Response.Write ("</tr></td></table><p>" How much more water would there be in the ocean if it weren't for sponges?
NO DEPARTMENT DEFINED:
fred jones
suzy smith
john doe
SALES:
john johnson
bobby brown
sid vicious
MARKETING
Joe joes
etc.
etc.
However there is a problem with the NO DEPARTMENT DEFINED part of the code. If, in the databse, the departmentID field is blank (isnull function), I want it to group under a single heading called NO DEPARTMENT DEFINED. But it is contiually coming out as:
NO DEPARTMENT DEFINED:
fred jones
NO DEPARTMENT DEFINED:
suzy smith
NO DEPARTMENT DEFINED:
john doe
SALES:
john johnson
bobby brown
sid vicious
MARKETING
Joe joes
etc.
etc.
Maybe I've been looking at this code for too long and have lost the ability to see what must be a fairly simple error in my loop. Can someone help me? Case 2 in the code below is where I believe the problem begins.
Do While rsEmployees.EOF = False
Select Case Session("GroupBy"
Case 0:
Case 1:
If LocationID <> rsEmployees("LocationID" Then
Response.Write (" <TR>"
Response.Write (" <TD></TD>"
Response.Write (" <TD valign=top><font size=-1>"
Response.Write (" "
Response.Write (" </TD>"
Response.Write (" <TD></TD>"
Response.Write (" </TR>"
Response.Write (" <TR>"
Response.Write (" <TD></TD>"
Response.Write (" <TD colspan=2 valign=top><font face=""Arial, Helvetica, sans-serif"" size=2><B>"
Response.Write ( rsEmployees("Branch" & "<BR> " & rsEmployees("City" & ", " & rsEmployees("State")
Response.Write (" </B></TD>"
Response.Write (" <TD></TD>"
Response.Write (" </TR>"
End If
LocationID = rsEmployees("LocationID"
Case 2:
If DepartmentID <> rsEmployees("DepartmentID" Then
Response.Write (" <TR>"
Response.Write (" <TD></TD>"
Response.Write (" <TD valign=top><font size=-1>"
Response.Write (" "
Response.Write (" </TD>"
Response.Write (" <TD></TD>"
Response.Write (" </TR>"
Response.Write (" <TR>"
Response.Write (" <TD></TD>"
Response.Write (" <TD colspan=2 valign=top><font face=""Arial, Helvetica, sans-serif"" size=2><B>"
Response.Write ( rsEmployees("Department")
Response.Write (" </B></TD>"
Response.Write (" <TD></TD>"
Response.Write (" </TR>"
else
End if
'Else
If isnull(rsEmployees("DepartmentID") Then
'DepartmentID="No Department Defined"
Response.Write (" <TR>"
Response.Write (" <TD></TD>"
Response.Write (" <TD valign=top><font size=-1>"
Response.Write (" "
Response.Write (" </TD>"
Response.Write (" <TD></TD>"
Response.Write (" </TR>"
Response.Write (" <TR>"
Response.Write (" <TD></TD>"
Response.Write (" <TD colspan=2 valign=top><font face=""Arial, Helvetica, sans-serif"" size=2><B>"
Response.Write ( "No Department Defined"
Response.Write (" </B></TD>"
Response.Write (" <TD></TD>"
Response.Write (" </TR>"
' End If
' If rsEmployees("DepartmentID"="" then
' DepartmentID = rsEmployees("DepartmentID"
else
departmentID=rsEmployees("DepartmentID"
end if
End Select
Response.Write (" <TR>"
Response.Write (" <TD></TD>"
Response.Write (" <TD valign=top><font face=""Arial, Helvetica, sans-serif"" size=2>"
Response.Write (" <a href=employee.asp?r=" & Rand() & "&EmployeeID=" & rsEmployees("EmployeeID" & "&command=Edit>" & rsEmployees("Fullname" & "</a>"
Response.Write (" </TD>"
Response.Write (" <TD><font face=""Arial, Helvetica, sans-serif"" size=2>"
Response.Write ( rsEmployees("Priority")
Response.Write (" </TD>"
Response.Write (" <TD></TD>"
Response.Write (" </TR>"
rsEmployees.MoveNext
Loop
Response.Write ("</TABLE>"
Response.Write ("</tr></td></table>"
Response.Write ("</tr></td></table><p>" How much more water would there be in the ocean if it weren't for sponges?