Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: array question


Message #1 by "Michael Goldman" <mg188@h...> on Thu, 23 Nov 2000 13:47:54 -0800
Hi,



Two comma-delimited arrays, AR1 and AR2 are each built by looping through

the recordset of a different table.  The 2 arrays could have different

numbers of entries.  I want to take the intersection of these arrays and

delete records with those values from the db.  For example, if "pink socks"

exists in both arrays, I want to delete those records.  If "pink socks"

exists in only one array, I DON'T want to delete it.  I'll run this test

serverside.



thanks in advance.



Message #2 by "Dallas Martin" <dmartin@z...> on Thu, 23 Nov 2000 20:49:48 -0500
I don't think this question belongs here. But anyway, it is fairly simple to

program.



I assume you are running ASP on NT/W2K. If so, then it rather easy to code

the solution.



'some code to create and open the connection

oConn = Server.CreateObject("ADODB.Connection")

oConn.Open("DSN=whatever") ' or oledb driver string



arrLen1 = Ubound(Array1)

arrLen2 = Ubound(Array2)



for x = 0 to arrLen1 -1

     strFind = Array1(x)

     for y = 0 to arrLen2 - 1

          if strFind = Array(y)

             ' some code to delete record in database

              sql = "DELETE table WHERE condition = whatever"

              oConn.Execute(sql)

              'some code to check for errors

             if err.number <> 0 then

                ' do whatever

             end if

         end if

   next

next



' close the connection

oConn.Close

Set oConn = Nothing



hth,

Dallas Martin



















----- Original Message -----

From: "Michael Goldman" <mg188@h...>

To: "ASP Databases" <asp_databases@p...>

Sent: Thursday, November 23, 2000 4:47 PM

Subject: [asp_databases] array question





> Hi,

>

> Two comma-delimited arrays, AR1 and AR2 are each built by looping through

> the recordset of a different table.  The 2 arrays could have different

> numbers of entries.  I want to take the intersection of these arrays and

> delete records with those values from the db.  For example, if "pink

socks"

> exists in both arrays, I want to delete those records.  If "pink socks"

> exists in only one array, I DON'T want to delete it.  I'll run this test

> serverside.

>

> thanks in advance.

>



Message #3 by "Ken Schaefer" <ken@a...> on Fri, 24 Nov 2000 12:48:31 +1100
How about you run an SQL query that only selects records from table1, if

they also exist in table2?



Eg



SELECT field1, field2

FROM table1

WHERE field1 IN

    (SELECT field1

    FROM table2

    WHERE foo = 'bar')



This should give you one recordset with only the records that are in both

tables.



Then, loop through this to create two SQL statements that are DELETE FROM

table1 and DELETE FROM table2, and execute the two SQL statements.



I think you'll find this is less expensive.



Cheers

Ken



----- Original Message -----

From: "Michael Goldman" <mg188@h...>

To: "ASP Databases" <asp_databases@p...>

Sent: Friday, November 24, 2000 8:47 AM

Subject: [asp_databases] array question





> Hi,

>

> Two comma-delimited arrays, AR1 and AR2 are each built by looping through

> the recordset of a different table.  The 2 arrays could have different

> numbers of entries.  I want to take the intersection of these arrays and

> delete records with those values from the db.  For example, if "pink

socks"

> exists in both arrays, I want to delete those records.  If "pink socks"

> exists in only one array, I DON'T want to delete it.  I'll run this test

> serverside.

>

> thanks in advance.





Message #4 by "jigs gandhi" <newsgroup@h...> on Fri, 24 Nov 2000 09:40:07 +0530
This is a multi-part message in MIME format.



------=_NextPart_000_0142_01C055FA.880FDDA0

Content-Type: text/plain;

	charset="iso-8859-1"

Content-Transfer-Encoding: quoted-printable



hi,



i would suggest you to get only one recordset.

else

hope this helps



'initialize the string

strDeleteThem =3D ""

'loop thru both the arrays

for i =3D lBound(firstarray) to ubound(firstarray)

    for j =3D lBound(secondarray) to ubound(secondarray)

        if secondarray(j) =3D firstarray(i) then

            strDeleteThem =3D strDeleteThem & secondarray(j) & ","

            'set the value to "" to avoid repeatitions

            secondarray(j) =3D ""

        end if

    next

next

' delete the last comma

strDeleteThem =3D left(strDeleteThem,len(strDeleteThem)-1)

sqlDelete =3D "delete from tablename where columnname in (" & 

strDeleteThem & ")"





jigs



  ----- Original Message -----

  From: Michael Goldman

  To: ASP Databases

  Sent: Friday, November 24, 2000 3:17 AM

  Subject: [asp_databases] array question





  Hi,



  Two comma-delimited arrays, AR1 and AR2 are each built by looping 

through

  the recordset of a different table.  The 2 arrays could have different

  numbers of entries.  I want to take the intersection of these arrays 

and

  delete records with those values from the db.  For example, if "pink 

socks"

  exists in both arrays, I want to delete those records.  If "pink 

socks"

  exists in only one array, I DON'T want to delete it.  I'll run this 

test

  serverside.



  thanks in advance.





  ---

  FREE WEB DEVELOPMENT CODE, CONTENT, AND INSIGHTS

  IN YOUR INBOX!

  Get the latest and best HTML, XML, and JavaScript tips, tools, and

  developments from the experts.  Sign up for one or more of EarthWeb's

  FREE IT newsletters at http://www.earthweb.com today! 




$subst('Email.Unsub')











  Return to Index