Hi!
I have a page that selects one or more "sourcecodes" from one table, then uses that recordset in another select ....
the queries are working, but when there is more than one sourcecode, my output is just the last one repeated ....
can anyone see what i might be doing wrong with the loops?
or ??
thanks,
(code below...............)
SQL= "SELECT listinfo.SourceCode, listinfo.BreakEven, listinfo.MailingDate, listinfo.Category " &_
" FROM listinfo " &_
" WHERE " &_
"MailingDate = #" & strMDate & "#" & " And Category = '" & strCategory & "' " '&_
'"Order BY listinfo.sourcecode"
set RS1 = objConn.execute(SQL)
strCode = rs1("SourceCode"
strBreak = rs1("BreakEven"
strMDate = rs1("MailingDate"
strCategory = rs1("Category"
'write out table header...............
Response.Write "<html>" & vbCrLf & "<head><title> Reports</title>" & vbCrLf &_
"<style>" & vbCrLf &_
" BODY { background: #D8D8BF; color: black; font-size: 9pt; font-family: arial, sans-serif; }" & vbCrLf &_
" TABLE { color: black; font-size: 9pt; font-family: arial, sans-serif; }" & vbCrLf &_
" TH { color: black; font-size: 9pt; font-family: arial, sans-serif; }" & vbCrLf &_
" TD { color: black; font-size: 9pt; font-family: arial, sans-serif; }" & vbCrLf &_
" P { color: black; font-size: 9pt; font-family: arial, sans-serif; }" & vbCrL &_
" .success { color: #009900; font-weight: bold; }" & vbCrLf &_
" .error { color: #FF3333; font-weight: bold; }" & vbCrLf &_
"</style>" & vbCrLf & "</head>" & vbCrLf
Response.Write "<body>" & vbCrLf
Response.Write "<a href=""SCj.asp""><< Select Menu</a></p><center>" & vbCrLf
Response.Write "<font size=+1>Mailing Date: " & strMDate & " and Category: " & strCategory & "</h3></font><br>" & vbCrLf
'display table head
Response.Write "<table BORDER='0' cellspacing='1' cellpadding='2' style='font-family: Arial; font-size: 8pt' bgcolor='#dddddd'><tr>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b>Source code</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b>Break Even</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b># Sales</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b># Returns</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b># Refunds</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b># Net Sales</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b>% Success</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b>% Returns</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b>% Refunds</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b>$ Sales</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b>$ Refunds</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b>$ Net Sales</b></td>" & vbCrLf
Response.Write "</tr>" & vbCrLf
do until rs1.eof
'*************************************************
If Len(Request("Page") > 0 Then
intPage = Request("Page"
lngFirstRec = (intPage-1) * 100 + 1
Else
intPage = 1
lngFirstRec = 1
End If
OpenDB
Set oRSp=Server.CreateObject("ADODB.Recordset"
oRSp.LockType = 1 'adLockReadOnly
oRSp.CursorType = 1 'adOpenKeyset
strSourceCode = strCode
'code - specific SQL
strSQL = "SELECT DISTINCT Ordr.Order_Number, Ordr.Order_Date, Cust.First_Name, Cust.Last_Name, " &_
"Cust.State, Paym.Paid_Amount, " &_
"Retn.Return_Date, Retn.Sale_Amount, Rfnd.Refund_Date, Rfnd.Refund_Amount " &_
"FROM (((Ordr INNER JOIN Cust ON Ordr.Order_Number = Cust.Order_Number) " &_
"INNER JOIN Paym ON Paym.Order_Number= Cust.Order_Number) " &_
"LEFT JOIN Rfnd ON Ordr.Order_Number = Rfnd.Order_Number) " &_
"LEFT JOIN Retn ON Rfnd.Order_Number = Retn.Order_Number " &_
"WHERE Cust.Record_Type='CUST' "
'full retrieval SQL for comparative % calculation
'strSQLAll = strSQL
'use selected source code if specified, otherwise retrieve all
If Len(Trim(strSourceCode)) > 0 Then
strSQL = strSQL & "AND Ordr.Source_Code LIKE '" & strSourceCode & "%' "
End If
'Run the search
oRSp.Open strSQL, objConn
curPayTotal = 0
curRefundTotal = 0
If Not oRSp.BOF Then
blnFound = True
oRSp.MoveFirst
End If
' count up all the sales for this code
Do Until oRSp.EOF
If oRSp("Paid_Amount" > 0 Then
curPayTotal = curPayTotal + oRSp("Paid_Amount"
lngSaleTotal = lngSaleTotal + 1
End If
If oRSp("Refund_Amount" > 0 Then
curRefundTotal = curRefundTotal + oRSp("Refund_Amount"
lngRefundTotal = lngRefundTotal + 1
End If
If oRSp("Sale_Amount" > 0 Then
lngReturnTotal = lngReturnTotal + 1
End If
oRSp.MoveNext
Loop
oRSp.Close
strDisplaySourceCode = strSourceCode
'begin page
'display per-code content
Response.Write "<tr>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle"">" & strDisplaySourceCode & " </td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & strBreak & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & lngSaleTotal & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & lngReturnTotal & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & lngRefundTotal & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & FormatNumber(lngSaleTotal-lngRefundTotal,0) & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & FormatNumber(lngSaleTotal-lngRefundTotal,0) & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & FormatPercent(lngReturnTotal/lngSaleTotal) & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & FormatPercent(lngRefundTotal/lngSaleTotal) & "</td>"
Response.Write "<td bgcolor=""white"" align=""middle""> " & FormatCurrency(curPayTotal,2) & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & FormatCurrency(curRefundTotal,2) & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & FormatCurrency(curPayTotal-curRefundTotal,2) & "</td>" & vbCrLf
rs1.movenext
loop
'end table
Response.Write "</table>" & vbCrLf
'end the page
Response.Write "</center></body>" & vbCrLf & "</html>" & vbCrLf
rs1.close
set rs1=nothing
%>
I have a page that selects one or more "sourcecodes" from one table, then uses that recordset in another select ....
the queries are working, but when there is more than one sourcecode, my output is just the last one repeated ....
can anyone see what i might be doing wrong with the loops?
or ??
thanks,
(code below...............)
SQL= "SELECT listinfo.SourceCode, listinfo.BreakEven, listinfo.MailingDate, listinfo.Category " &_
" FROM listinfo " &_
" WHERE " &_
"MailingDate = #" & strMDate & "#" & " And Category = '" & strCategory & "' " '&_
'"Order BY listinfo.sourcecode"
set RS1 = objConn.execute(SQL)
strCode = rs1("SourceCode"
strBreak = rs1("BreakEven"
strMDate = rs1("MailingDate"
strCategory = rs1("Category"
'write out table header...............
Response.Write "<html>" & vbCrLf & "<head><title> Reports</title>" & vbCrLf &_
"<style>" & vbCrLf &_
" BODY { background: #D8D8BF; color: black; font-size: 9pt; font-family: arial, sans-serif; }" & vbCrLf &_
" TABLE { color: black; font-size: 9pt; font-family: arial, sans-serif; }" & vbCrLf &_
" TH { color: black; font-size: 9pt; font-family: arial, sans-serif; }" & vbCrLf &_
" TD { color: black; font-size: 9pt; font-family: arial, sans-serif; }" & vbCrLf &_
" P { color: black; font-size: 9pt; font-family: arial, sans-serif; }" & vbCrL &_
" .success { color: #009900; font-weight: bold; }" & vbCrLf &_
" .error { color: #FF3333; font-weight: bold; }" & vbCrLf &_
"</style>" & vbCrLf & "</head>" & vbCrLf
Response.Write "<body>" & vbCrLf
Response.Write "<a href=""SCj.asp""><< Select Menu</a></p><center>" & vbCrLf
Response.Write "<font size=+1>Mailing Date: " & strMDate & " and Category: " & strCategory & "</h3></font><br>" & vbCrLf
'display table head
Response.Write "<table BORDER='0' cellspacing='1' cellpadding='2' style='font-family: Arial; font-size: 8pt' bgcolor='#dddddd'><tr>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b>Source code</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b>Break Even</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b># Sales</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b># Returns</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b># Refunds</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b># Net Sales</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b>% Success</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b>% Returns</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b>% Refunds</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b>$ Sales</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b>$ Refunds</b></td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""><b>$ Net Sales</b></td>" & vbCrLf
Response.Write "</tr>" & vbCrLf
do until rs1.eof
'*************************************************
If Len(Request("Page") > 0 Then
intPage = Request("Page"
lngFirstRec = (intPage-1) * 100 + 1
Else
intPage = 1
lngFirstRec = 1
End If
OpenDB
Set oRSp=Server.CreateObject("ADODB.Recordset"
oRSp.LockType = 1 'adLockReadOnly
oRSp.CursorType = 1 'adOpenKeyset
strSourceCode = strCode
'code - specific SQL
strSQL = "SELECT DISTINCT Ordr.Order_Number, Ordr.Order_Date, Cust.First_Name, Cust.Last_Name, " &_
"Cust.State, Paym.Paid_Amount, " &_
"Retn.Return_Date, Retn.Sale_Amount, Rfnd.Refund_Date, Rfnd.Refund_Amount " &_
"FROM (((Ordr INNER JOIN Cust ON Ordr.Order_Number = Cust.Order_Number) " &_
"INNER JOIN Paym ON Paym.Order_Number= Cust.Order_Number) " &_
"LEFT JOIN Rfnd ON Ordr.Order_Number = Rfnd.Order_Number) " &_
"LEFT JOIN Retn ON Rfnd.Order_Number = Retn.Order_Number " &_
"WHERE Cust.Record_Type='CUST' "
'full retrieval SQL for comparative % calculation
'strSQLAll = strSQL
'use selected source code if specified, otherwise retrieve all
If Len(Trim(strSourceCode)) > 0 Then
strSQL = strSQL & "AND Ordr.Source_Code LIKE '" & strSourceCode & "%' "
End If
'Run the search
oRSp.Open strSQL, objConn
curPayTotal = 0
curRefundTotal = 0
If Not oRSp.BOF Then
blnFound = True
oRSp.MoveFirst
End If
' count up all the sales for this code
Do Until oRSp.EOF
If oRSp("Paid_Amount" > 0 Then
curPayTotal = curPayTotal + oRSp("Paid_Amount"
lngSaleTotal = lngSaleTotal + 1
End If
If oRSp("Refund_Amount" > 0 Then
curRefundTotal = curRefundTotal + oRSp("Refund_Amount"
lngRefundTotal = lngRefundTotal + 1
End If
If oRSp("Sale_Amount" > 0 Then
lngReturnTotal = lngReturnTotal + 1
End If
oRSp.MoveNext
Loop
oRSp.Close
strDisplaySourceCode = strSourceCode
'begin page
'display per-code content
Response.Write "<tr>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle"">" & strDisplaySourceCode & " </td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & strBreak & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & lngSaleTotal & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & lngReturnTotal & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & lngRefundTotal & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & FormatNumber(lngSaleTotal-lngRefundTotal,0) & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & FormatNumber(lngSaleTotal-lngRefundTotal,0) & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & FormatPercent(lngReturnTotal/lngSaleTotal) & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & FormatPercent(lngRefundTotal/lngSaleTotal) & "</td>"
Response.Write "<td bgcolor=""white"" align=""middle""> " & FormatCurrency(curPayTotal,2) & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & FormatCurrency(curRefundTotal,2) & "</td>" & vbCrLf
Response.Write "<td bgcolor=""white"" align=""middle""> " & FormatCurrency(curPayTotal-curRefundTotal,2) & "</td>" & vbCrLf
rs1.movenext
loop
'end table
Response.Write "</table>" & vbCrLf
'end the page
Response.Write "</center></body>" & vbCrLf & "</html>" & vbCrLf
rs1.close
set rs1=nothing
%>