Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Repeating display data... 2

Status
Not open for further replies.

A1Pat

IS-IT--Management
Jun 7, 2004
454
US
Hello,
This calling of mine keep displaying a result, which I know for sure only 1 data, again and again and again for pages. Could someone tell me where I went wrong here:

mySQL = "SELECT b.idOrder " _
& "FROM customer a, cartHead b " _
& "WHERE a.idCust = b.idCust " _
& " AND a.tempCust = 'Y'"
set rs = openRSexecute(mySQL)
do while not rs.eof
response.write rs("idOrder") & "<BR>"
loop
call closeRS(rs)
response.End()
 
your problem is probably caused by:

[tt]FROM Customer a, cartHead b[/tt]

this is a cartesian join and basically multiples all the records from Customer by all the records in cartHead.

This may work:
Code:
mySQL = "SELECT b.idOrder " _
          & "FROM   customer a " _
          & "INNER JOIN CartHead b ON a.idCust = b.idCust " _
          & "WHERE  a.tempCust = 'Y'"
    set rs = openRSexecute(mySQL)
    do while not rs.eof
        response.write rs("idOrder") & "<BR>"
    loop
    call closeRS(rs)
    response.End()

or if you only want a SINGLE idOrder for each, add DISTINCT:

Code:
mySQL = "SELECT DISTINCT b.idOrder " _
          & "FROM   customer a " _
          & "INNER JOIN CartHead b ON a.idCust = b.idCust " _
          & "WHERE  a.tempCust = 'Y'"
    set rs = openRSexecute(mySQL)
    do while not rs.eof
        response.write rs("idOrder") & "<BR>"
    loop
    call closeRS(rs)
    response.End()



Leslie

Anything worth doing is a lot more difficult than it's worth - Unknown Induhvidual

Essential reading for anyone working with databases:
The Fundamentals of Relational Database Design
Understanding SQL Joi
 
First, thank you Leslie for your input.

I'd already tried using Inner Join but since I realize there's only 1 idOrder for every idCust; hence, I changed the code to this one.

However, to make sure, I tried again with the code given and the result is still exactly the same.

:-(
 
try
Code:
    do while not rs.eof
        response.write rs("idOrder") & "<BR>"
      [b]rs.movenext[/b]
    loop
:)

Greg
"Personally, I am always ready to learn, although I do not always like being taught." - Winston Churchill
 
hahahah... you right Leslie, Greg catch the good one. My BAD!!!

Thank you both!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top