recursive loop (PLEAAAASSEEEE!!!!!!!!)

Results 1 to 2 of 2

Thread: recursive loop (PLEAAAASSEEEE!!!!!!!!)

  1. #1
    cindy Guest

    Default recursive loop (PLEAAAASSEEEE!!!!!!!!)

    hi,<BR><BR>i need to creat a loop that will do what the following does in psuedocode...<BR>get recordset1 from database1<BR>for each record in recordset1<BR> create record in database2<BR> query database1 to see if any parents exist for record<BR> (if any parents exist populate them as well and check to see if they have parents)<BR><BR>this loop goes on infinitely until there are no parents found<BR><BR>i have no clue how to do this, i started to come up with some random nonsense that i have put below but i know its not going to work, please help...<BR><BR>if not rstParents.EOF then<BR> do while not rstParents.EOF<BR> parent(rstParents("pin"))<BR> <BR> &#039;update new parent record<BR> rstParents.movenext<BR> loop<BR> <BR>function parent(N)<BR> strSQL = ""<BR> Call BuildParam(strSQL, "@pin", N, true, False) <BR> strSQL = "exec pin_parent_finder " & strSQL<BR> cmdDB.commandtext = strSQL<BR> set rstParents2 = cmdDB.execute<BR> if not rstParents2.EOF then<BR> do while not rstParents2.EOF<BR> parent(rstParents2("pin")<BR> rstParents2.movenext<BR> loop<BR> <BR> exit function<BR> end if<BR> <BR>end function<BR><BR>loop

  2. #2
    Join Date
    Dec 1969

    Default Bad idea...

    You really need to find a way to do this that does *NOT* involve recursive calls to open recordsets. It is *VERY* expensive to do that, puts a big burden on the databases, etc., etc.<BR><BR>If the number of records in the source database isn&#039;t *too* big, you&#039;d probably be better off reading *all* the records into an array (see ADODB.RecordSet.GetRows) and then processing the array with VBS code...yes, using recursion if need be. But at least only the VBS is recursive, not the recordset processing.<BR><BR>It would *probably* be from 20 to 200 times faster this way.<BR><BR>You *might* even consider building an index into the array to find the parents, depending on the number of records. You could use a Scripting.Dictionary for this with ease and perhaps gain a bunch in performance. <BR><BR>But I simply can NOT think that doing it the way you are attempting is a very good idea, at all. Sorry.<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