
Comparing Records in Recordset
Ok I have gone brain dead, and cant get it to work, so I am asking for help.....I have pulled a 2 ordinal recordset that has names and number that I would like to add together.. It is grouped by name so that all duplicate entries will show up together. I am needing a piece of code that will iterate through and compare each record to the next (determining when to quit adding), then begin recounting on the next occurrence of the name. I have been trying to get it all day......rstemp2(0) is the name and rstemp(1) is the number, Please help...This is what the recordset result looks like:<BR><BR>Alan Bellamy 6<BR>Alan Bellamy 8<BR>Alan Bellamy 11<BR>Alan Bellamy 17<BR>Betty Munsell 5<BR>Bill Anderson 2<BR>Bill Anderson 6<BR>Bill Anderson 12<BR>Brett Grybowski 1<BR>Brett Grybowski 6<BR>Brett Grybowski 7<BR>Brett Grybowski 12<BR>Brett Grybowski 13<BR>Bryan Williams 2<BR>Bryan Williams 4<BR>Bryan Williams 7<BR>Carla Welt 5<BR>Carla Welt 12<BR>Carol Dubois 3<BR>Chad Choate 4<BR>Chad Hester 7<BR>Chad Hester 9<BR>Clint Pebsworth 4<BR>Clint Pebsworth 13<BR>Craig Robertson 4<BR>Craig Robertson 5<BR>Craig Robertson 6<BR>Craig Robertson 25<BR>Curtis Simpson 7<BR>Darell Ogletree 2<BR>Darell Ogletree 3<BR>Darell Ogletree 6<BR>Darell Ogletree 8<BR>Don Crownover 5<BR>Dustin Brecheen 3<BR>Dustin Brecheen 16<BR><BR>Here is the code I have so far...PLEASE HELP<BR> <BR><BR>'DO until rstemp2.eof <BR>'adj = rstemp2(0)<BR>'rstemp2.movenext<BR>'adjc = rstemp2(0)<BR>'if adjc = "" then <BR>'end if<BR>'else<BR>'if StrComp(adj,adjc,1) = 0 then<BR>'dayz = dayz + rstemp2(1)<BR>'rstemp2.moveprevious<BR>' else <BR>'end if<BR>'response.write adj & " " & dayz<BR><BR>'loop

GroupBy
Can you do a groupby when you retrieve the recordset?<BR><BR>SQL="Select Name, Sum(Score) as Total from ...... Group By Name"<BR><BR><BR>

Alternatively, you could
use Getstring. Assuming for the sake of argument that you CAN'T use a groupby, you Could use Getstring and a regular expression to find all the similar names with the attendant number to add<BR><BR> <BR><BR><BR>

RE: Alternatively, you could
Right, but I am mainly concerned in adding the like records together, for example the first is Alan Bellamy and he has 4 occurences which add to be 42, I want the code to add all these together then display his name and that total, then move to the next record and do the same for the rest of the recordset, I hope I make sense?? I almost have it, but cant quite get it to work, it just times out, but I cant figure where I am going wrong..I rewrote it 5 mins ago...<BR><BR><BR>'Do until rstemp2.eof<BR>' strCurrentName = rstemp2(0)<BR>' If strName <> strPreviousName Then<BR>' If iCounter <> 0 Then<BR>' Response.Write strPreviousName & " " & iCounter<BR>' End If<BR>' strPreviousName = rstemp2(0)<BR>' Else<BR>' iCounter = iCounter + rstemp2(1)<BR>' End If<BR>' iCounter = 0<BR>'Loop<BR>'Do this again to catch the last entry in the list.<BR>'Response.Write strPreviousName & " " & iCounter<BR><BR><BR>It times out though after like 5 mins...UGH..Please help

Well, if you can't do it in SQL
then for crying out loud at least use getrows.<BR><BR>aryTemp0=Rsttemp.GetRows<BR>i=ubou nd(aryTemp0,2)<BR>ThisName=aryTemp0(0,0)<BR>for j = 0 to i<BR> if ThisName=aryTemp0(j,0) then<BR> ThisScore=ThisScore+aryTemp0(j,1)<BR> else<BR> response.write Thisname & " " & thisScore & "<P>"<BR> thisscore=aryTemp0(J,1)<BR> thisname=aryTemp0(j,0)<BR> end if<BR>next<BR>

Why would you *NOT* use SUM?
And GROUP BY???<BR><BR>Is there some *OTHER* reason that you need all the info in all the records?<BR><BR>Oh...and your code times out because you don't have any MOVENEXT in that loop!<BR><BR>(The code's wrong, too, but that's a different issue. Answer the question about SUM first.)<BR><BR>

You have rows and columns backwards
Remember, with GetRows the column number comes *first*!<BR><BR>*ALL* of your "j" indices should be the second index of the array elements.<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

Forum Rules

