Nested SQL Loops in Classic ASP
Posted on 2008-06-16
I've got an issue where I am pulling out an inital SQL query that yields the following results (rs2) :
I want to then separate this result into two queries somehow based on JobID, or for example if there was 10 records with 5 different jobids then separate it out into five queries (loops may make more sense once you see the code below). This is why I've tried nesting the two loops however it doesn't work as once it's completed the first inner loop it then tries to loop again on the outer loop by from the first jobid again and not the next one. How can I get around this?
set rs2 = objConn.execute( "SELECT JobID, Hyperlink FROM QryJobHyperlinks WHERE JobShellId=" & strJobShellID & " and JobPage = '" & strJobPage & "'")
do while not rs2.eof or rs2.bof
set rs = objConn.execute( "SELECT JobID, Hyperlink, HyperlinkID, JobPage, DateUploaded FROM QryJobHyperlinks WHERE JobId=" & rs2("JobID") & " and JobPage = '" & strJobPage & "'")
<table width="100%" border="0" cellPadding="3" cellSpacing="3" class="DisplayTaskTable">
<% do while not rs.eof or rs.bof %>
<table width="100%" border=0 cellPadding=3 cellSpacing=3 class="DisplayTaskTable">
<td colspan="5" height="30" class="bodyheader"><%=rs("Hyperlink")%></td>
Many thanks in advance.