Comparing record to next record

Results 1 to 2 of 2

Thread: Comparing record to next record

  1. #1
    Join Date
    Dec 1969

    Default Comparing record to next record

    Okay, I am querying an Excel document that has several of which is a sku column. I have the document ordered by sku. What I want to do is compare the sku the next sku in an attempt to see if they are the same or not. But, my code ain&#039;t working...any ideas why? Below is my if statement. Mind you this is enclosed in a "do while not rs.eof" loop. <BR><BR>&#060;%<BR>sku1 = rs("sku")<BR>rs.movenext<BR>sku2 = rs("sku")<BR>rs.moveprevious<BR><BR>if sku1 = sku2 then<BR>response.write "&#060;tr&#062;&#060;td colspan=6&#062;^^^^^^DING DING DING...WE HAVE A WINNER!!!^^^^^^"<BR>response.write rs("sku")<BR>response.write "&#060;/td&#062;&#060;/tr&#062;"<BR>badcount = badcount + 1<BR>else<BR> <BR>End If<BR>%&#062;<BR><BR><BR>Thanks Guys,<BR>FerretWorks

  2. #2
    Join Date
    Dec 1969

    Default You can't do MovePrevious...

    ...with Excel. At least I&#039;m pretty sure of that.<BR><BR>The easiest way to fix this would be to convert the recordset to an array using GetRows and then simply compare adjacent rows in the 2D array.<BR><BR>Barring that, best thing to do would be something like this:<BR><BR>&#060;%<BR>priorSKU = ""<BR>Do Until RS.EOF<BR>&nbsp; &nbsp; curSKU = RS("SKU")<BR>&nbsp; &nbsp; If curSKU = priorSKU Then<BR>&nbsp; &nbsp; &nbsp; &nbsp; Response.Write "We have a winner..." & priorUserName ...<BR>&nbsp; &nbsp; &nbsp; &nbsp; End Do<BR>&nbsp; &nbsp; End If<BR>&nbsp; &nbsp; priorSKU = RS("SKU")<BR>&nbsp; &nbsp; priorUserName = RS("userName")<BR>&nbsp; &nbsp; prior... = RS(...)<BR>&nbsp; &nbsp; RS.MoveNext<BR>Loop<BR>%&#062;<BR><BR>See the idea? You save *all* the info from the "prior record" so that you can use it if, the next time through the loop, you get a "hit".<BR><BR>

Posting Permissions

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