Looping woes

Results 1 to 2 of 2

Thread: Looping woes

  1. #1
    Join Date
    Dec 1969

    Default Looping woes

    Hey all,<BR><BR>I&#039;m trying to create a report of some publications I have in a table. The pubs have a category name, which they are grouped by, so I have data that looks like this:<BR>________________________________<BR>Descr iption &#124&#124 Category &#124 <BR>--------------------------------&#124<BR>Binge Drinking &#124&#124 Alcohol &#124<BR>Alcohol self test &#124&#124 Alcohol &#124<BR>Sleep &#124&#124 Other &#124<BR>__________________&#124&#124____________& #124<BR><BR>But I want the report to look like:<BR><BR>Alcohol<BR>-------Alcohol Self Test<BR>-------Binge Drinking<BR>Other<BR>-------Sleep<BR><BR>...and so on. Am I making sense at this point? Basically while the category = X, dump each title, then move on to the next category.<BR><BR>Right. Now, I&#039;ve written this loop before, and it worked, but this time its not going too peachy. Here is the SQL Query I&#039;m using, for a reference:<BR><BR>Cm = "SELECT SUM(PBDAORSB.Quantity) AS OrderQ, SUM(PBDADSTB.Quantity) AS DistQ, PBLBCATG.CategoryID, PBDAITEM.Description, PBDAITEM.Price, PBLBCATG.Category, PBDAVEND.Vendor FROM PBLBCATG INNER JOIN PBDAITEM ON PBLBCATG.CategoryID = PBDAITEM.CategoryID LEFT OUTER JOIN PBDADSTB ON PBDAITEM.PubID = PBDADSTB.PubID LEFT OUTER JOIN PBDAORSB INNER JOIN PBDAORDR ON PBDAORSB.OrderID = PBDAORDR.OrderID INNER JOIN PBDAVEND ON PBDAORDR.VendorID = PBDAVEND.VendorID ON PBDAITEM.PubID = PBDAORSB.PubID WHERE (PBDAORSB.DateDelivered BETWEEN &#039;" & StartDate & "&#039; AND &#039;" & EndDate & "&#039;) OR (PBDADSTB.Date BETWEEN &#039;" & StartDate & "&#039; AND &#039;" & EndDate & "&#039;) GROUP BY PBDAITEM.Description, PBDAITEM.Price, PBLBCATG.Category, PBLBCATG.CategoryID, PBDAVEND.Vendor ORDER BY PBLBCATG.Category"<BR><BR>Now, here is the ASP code I wrote to handle the loops:<BR><BR>Do While Not Rs.EOF //Main Loop<BR><BR>CatID = Rs("CategoryID") //Set the variable = to the current Category<BR><BR>Do While CatID = Rs("CategoryID") //Inner Loop<BR>Response.Write Rs("Category")<BR>Rs.MoveNext //Inner MoveNext<BR>Loop //Inner Loop<BR><BR><BR>Rs.MoveNext //Outer MoveNext<BR>Loop //Outer Loop<BR><BR><BR>The logic seems OK, but when I run the loop, I only get the FIRST category&#039;s results. It seems that its running through the inner loop and then breaking out. It gives me data, but not all of the data that the query returns. I&#039;m absolutely stuck. Am I missing something very obvious here?<BR><BR>Thanks!<BR>-Ryan<BR><BR>

  2. #2
    Join Date
    Dec 1969

    Default ASPFAQs.com

    Databases, General.<BR><BR>Has a FAQ on EXACTLY what you are trying to accomplish.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts