[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

7.0

sql syntax (looping table inside another one)

Asked by amucinobluedot in SQL Query Syntax, Active Server Pages (ASP), Adobe Dreamweaver

I have an ASP/VB script page that displays the results of a query (repeated region). Inside that region I am using some ASP code to display what would be a 'nested region', which are records from another recordset (one or more) that are related to the main table, problem is that the file that it creates is so big takes forever and crashes IE.  I want to see if this can be done with an sql query instead.

The main query is attached, and so is the second query, below is the code that displays the results. As you can see the ASP code goes through ALL of the second table records and see which ones are matched (linked in a relation) with the first one, then goes to the next record, second table has thousands of records so it takes forever, I need to join the two somehow and display those multiple records in just ONE field of the database instead of multiple ones.

--- code is here ---

<table width="100%" border="0" cellpadding="0" cellspacing="0">
         <thead><tr >
          <td bgcolor="eceef4"><img src="../../../Images/blank.gif" alt="" width="10" height="25"></td>
          <td width="19" bgcolor="eceef4"><div align="center"><font color="#666666"><strong>#</strong></font></div></td>
          <td valign="middle" bgcolor="eceef4"><table width="9" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              <td width="2" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
              <td width="10"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
            </tr>
          </table></td>
          <td bgcolor="eceef4"><div align="center"><strong><font color="#666666">Last Name</font></strong></div></td>
          <td bgcolor="eceef4"><table width="9" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              <td width="2" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
              <td width="10"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
            </tr>
          </table></td>
          <td bgcolor="eceef4"><div align="center"><strong><font color="#666666">First Name</font></strong></div></td>
          <td bgcolor="eceef4"><table width="9" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              <td width="2" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
              <td width="10"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
            </tr>
          </table></td>
          <td bgcolor="eceef4"><div align="center"><strong><font color="#666666">email</font></strong></div></td>
          <td bgcolor="eceef4"><table width="9" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              <td width="2" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
              <td width="10"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
            </tr>
          </table></td>
          <td bgcolor="eceef4"><div align="center"><strong><font color="#666666">Case #</font></strong></div></td>
          <td bgcolor="eceef4"><table width="9" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              <td width="2" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
              <td width="10"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
            </tr>
          </table></td>
          <td bgcolor="eceef4"><div align="center"><strong><font color="#666666">Process</font></strong></div></td>
          <td bgcolor="eceef4"><table width="8" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              <td width="1" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
              <td width="10"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
            </tr>
          </table></td>
          <td bgcolor="eceef4"><div align="center"><strong><font color="#666666">Status</font></strong></div></td>
          <td bgcolor="eceef4"><table width="9" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              <td width="2" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
              <td width="10"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
            </tr>
          </table></td>
          <td bgcolor="eceef4"><div align="center"><strong><font color="#666666">Filing date</font></strong></div></td>
          <td bgcolor="eceef4"><table width="12" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              <td width="10" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
              <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              </tr>
            </table></td>
          <td bgcolor="eceef4"><div align="center"><strong><font color="#666666">Approval date</font></strong></div></td>
          <td bgcolor="eceef4"><table width="12" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              <td width="10" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
              <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              </tr>
            </table></td>
          <td bgcolor="eceef4"><div align="center"><strong><font color="#666666">Expiration date</font></strong></div></td>
          <td bgcolor="eceef4"><table width="12" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              <td width="10" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
              <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              </tr>
            </table></td>
          <td width="61" bgcolor="eceef4"><div align="center"><strong><font color="#666666">Status Max date</font></strong></div></td>
          <td width="12" bgcolor="eceef4"><table width="12" border="0" cellpadding="0" cellspacing="0">
            <tr>
              <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              <td width="10" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
              <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              </tr>
            </table></td>
          <td width="141" bgcolor="eceef4"><div align="center"><strong><font color="#666666">Comments</font></strong></div></td>
        </tr>
        <tr>
          <td colspan="25"><img src="../../../Images/blank.gif" alt="" width="10" height="10"><img src="../../../Images/blank.gif" alt="" height="6"></td>
        </tr>
        <tr>
          <td colspan="25" background="../../../Images/menus/separatortop.gif"><img src="../../../Images/blank.gif" alt="" width="10" height="3"></td>
        </tr>
        <tbody>

       <%
 Dim RecordCounter
RecordCounter = 0
 Dim FlushCOunter
 FlushCounter = 0
%>
        <%
While ((Repeat1__numRows <> 0) AND (NOT Cases.EOF))
%>
          <tr  <%
      RecordCounter=RecordCounter + 1
      If RecordCounter Mod 2 = 1 Then
            Response.Write("bgcolor=#FBFBFB")
      End If
      %>
      bgcolor="#FFFFFF" onMouseOver="this.style.backgroundColor='#FFFFCC'" onMouseOut="this.style.backgroundColor=''">
            <td width="10">&nbsp;</td>
            <td><span class="bodytextreportsc">
              <%
' Display repeat region row count - By RobGT - http://robgt.com
varRobGT_Count = (Repeat1__index + Request("offset") + 1)
Response.Write(varRobGT_Count)
%>
            </span></td>
            <td width="12" valign="middle"><table width="9" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
                <td width="2" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
                <td width="10"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              </tr>
            </table></td>
            <td width="80" class="bodytextreports" ><%=(Cases.Fields.Item("LastNm").Value)%></td>
            <td width="12" class="bodytextreports" ><table width="9" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
                <td width="2" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
                <td width="10"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              </tr>
            </table></td>
            <td width="83" class="bodytextreports" ><%=(Cases.Fields.Item("FirstNm").Value)%></td>
            <td width="12" class="bodytextreports" ><table width="9" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
                <td width="2" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
                <td width="10"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              </tr>
            </table></td>
            <td width="104" class="bodytextreports" ><%=(Cases.Fields.Item("email").Value)%></td>
            <td width="12" class="bodytextreports" ><table width="9" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
                <td width="2" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
                <td width="10"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              </tr>
            </table></td>
            <td width="112" class="bodytextreports" ><a href="javascript:;" onClick="MM_openBrWindow('../../Cases/GeneralInfo/Updatecasedetails.asp?caseid=<%=(Cases.Fields.Item("Id").Value)%>','CaseDetails','menubar=yes,scrollbars=yes,resizable=yes,width=800,height=600')"><%=(Cases.Fields.Item("CaseId").Value)%></a></td>
            <td width="12" class="bodytextreports" ><table width="9" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
                <td width="2" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
                <td width="10"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              </tr>
            </table></td>
            <td width="163" class="bodytextreports" ><%=(Cases.Fields.Item("Processcatalog").Value)%></td>
            <td width="12" class="bodytextreports" ><table width="9" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
                <td width="2" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
                <td width="10"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              </tr>
            </table></td>
            <td width="52" class="bodytextreports" ><div align="center"><span class="bodytextreportsC"><%=(Cases.Fields.Item("Nistatus").Value)%></span></div></td>
            <td width="12" class="bodytextreports" ><table width="9" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
                <td width="2" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
                <td width="10"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
              </tr>
            </table></td>
            <td width="69" class="bodytextreports" ><div align="center"><span class="bodytextreportsC"><%= DoDateTime((Cases.Fields.Item("Filedon").Value), 2, 9225) %></span></div></td>
            <td width="12" class="bodytextreports" ><table width="12" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
                <td width="10" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
                <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
                </tr>
            </table></td>
            <td width="82" class="bodytextreports" ><div align="center"><span class="bodytextreportsC"><%= DoDateTime((Cases.Fields.Item("Approvedon").Value), 2, 9225) %></span></div></td>
            <td width="12" class="bodytextreports" ><table width="12" border="0" cellpadding="0" cellspacing="0">
              <tr>
                <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
                <td width="10" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
                <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
                </tr>
            </table></td>
            <td width="95" class="bodytextreports" ><div align="center"><span class="bodytextreportsC"><%= DoDateTime((Cases.Fields.Item("Validtodate").Value), 2, 9225) %></span></div></td>
            <td width="12"><div align="center">
              <table width="12" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
                  <td width="10" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
                  <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
                  </tr>
                </table>
            </div></td>
            <td width="61"  ><div align="center"><span class="bodytextreportsC"><%= DoDateTime((Cases.Fields.Item("NIVMaxStatus").Value), 2, 9225) %></span></div></td>
            <td ><div align="center">
              <table width="12" border="0" cellpadding="0" cellspacing="0">
                <tr>
                  <td width="4"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
                  <td width="4" height="14"><img src="../../../Images/menus/separator.gif" alt="" /></td>
                  <td width="10"><img src="../../../Images/blank.gif" alt="" width="4" height="25" /></td>
                </tr>
              </table>
            </div></td>
            <td width="141" ><span class="bodytextreports">
              <%
FilterParam = Cases.Fields.Item("Id").Value
Comments.Filter = "CaseID=" & FilterParam
While (NOT Comments.EOF)
%>
              <img src="../../Images/blankpurple.gif" alt="" width="5" height="4">&nbsp;&nbsp;<%=(Comments.Fields.Item("Comments").Value)%>
              <%
Comments.MoveNext()
Wend
%>
              &nbsp;</span></td>
          </tr>
          <tr>
          <td colspan="25" background="../../../Images/menus/separatortop.gif"><img src="../../../Images/blank.gif" alt="" width="10" height="3"></td>
        </tr>
          <%
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
 
  FlushCounter = FlushCounter + 1  
 
  If FlushCounter = 250 Then
    Response.Flush
    FlushCounter = 0
  End If
 
  Cases.MoveNext()
Wend
%>
 


       
      </table>



"Comments" is the field that repeats itself within the result.  Please let me know if there are any other questions.

Table # 1 Name: Cases
ID of table # 1 =  id

Table # 2 Casecomments:
id of table # 2 that links it to number 1 =  caseid

So if I was to simply join them would be:  

casecomments.caseid = cases.id

The thing with the join is that I get multiple records of the same 'case' (first table), one for each comment (using left join), I need to somehow display all this comments in just one field, maybe separated by a " - " or something of that sort.

Hope I explained myself.
Attachments:
 
Table # 1 query
 
 
Table # 2 query
 
 
Related Solutions
Keywords: sql syntax (looping table inside anoth…
 
Loading Advertisement...
 
[+][-]10/02/09 07:37 AM, ID: 25478318Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10/02/09 01:58 PM, ID: 25482141Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zones: SQL Query Syntax, Active Server Pages (ASP), Adobe Dreamweaver
Sign Up Now!
Solution Provided By: saoirse1916
Participating Experts: 1
Solution Grade: B
 
 
Loading Advertisement...
20091111-EE-VQP-89 - Hierarchy / EE_QW_3_20080625