Results 1 to 7 of 7
  1. #1
    Join Date
    Feb 2003
    Posts
    15

    Unanswered: how to add/append an array to an array

    Hi

    Could some help me with a little problem, I have used the .getrows method to convert a recorset to an array.

    but I also then want to open a second recordset with a different SQL criteria (but returning same data/values/types but with different results) and I want ot be able to add the results of the second .getrows to the previous array.


    very simply put I want ot do this

    array = rs.getrows

    array = array + rs2.getrows

    Thanks in advance ..

  2. #2
    Join Date
    Jan 2003
    Location
    London, England
    Posts
    106
    Adding two arrays like this would probably be a real pain. It would be easier for you to join the two sql-statements together using a stored procedure and tmp-table or something...
    Frettmaestro
    "Real programmers don't document, if it was hard to write it should be hard to understand!"

  3. #3
    Join Date
    Feb 2002
    Location
    San Francisco, CA
    Posts
    441
    try
    Code:
    Select blah blah blah
    
    union
    
    select blah blah blah
    This will join the two result sets together; I am assuming they have the same # of fields?

    or make a linked list.

    Anyway don't think asp supports dynamically re-sizing arrays??!

  4. #4
    Join Date
    Feb 2003
    Posts
    15
    Originally posted by rhs98
    try
    Code:
    Select blah blah blah
    
    union
    
    select blah blah blah
    This will join the two result sets together; I am assuming they have the same # of fields?

    or make a linked list.

    Anyway don't think asp supports dynamically re-sizing arrays??!
    Thanks for advice, I have managed to append additional arrays together using redim preserve which resizes the array to the size required but keeping the current values intact.

    I've then created a function to remove duplicates from the array but I might try to use UNION to join my SQL strings but how would I make sure the second did not bring back result found by the first SQL query

    Could you provide an example of where the DISTINCT would go in a UNION Join (I guess that is what I should use)

    Oh and I'm using MySQL so no procedures me thinks...

    Thanks

  5. #5
    Join Date
    Feb 2003
    Posts
    15
    Also would you know how to specify the point in an array at which you would want the function .getrows to start appending the recordset

    so if I had an array and wanted to append more data (which I am already doing but by looping through the recordset) at the point where I want the second set of data to be added..

    at the moment I use

    For i=(totalnumrecs-numrecs) To totalnumrecs
    If NOT rs.EOF Then
    RSarray(0,i)=rs("ID")
    RSarray(1,i)=rs("Name")
    RSarray(2,i)=rs("Telephone")
    rs.MoveNext
    End If
    Next

    but I would like to use

    RSarray(totalnumrecs-numrecs) = rs.GetRows


    (totalnumrecs-numrecs) is the place at which the new set of data should be added to the array which has 3 columns 0,1,2

    Hope that makes sense to someone.

    I would like to use UNION but I also like the fact that I now have a script which allows me to make an array from as many SQL strings as I please and I then remove the duplicates with another function.

    Any other thoughts ideas would be welcome...

  6. #6
    Join Date
    Feb 2002
    Location
    San Francisco, CA
    Posts
    441
    I cant remember what it is, but there is a union like command which displays the duplicates, or the rs with no duplicates. Will have a look on google in a sec.

  7. #7
    Join Date
    Feb 2002
    Location
    San Francisco, CA
    Posts
    441
    OUTER UNION
    concatenates the query results.

    UNION
    produces all unique rows from both queries.

    EXCEPT
    produces rows that are part of the first query only.

    INTERSECT
    produces rows that are common to both query results.
    http://216.239.53.100/search?q=cache...ng_en&ie=UTF-8

    hope this helps...

Posting Permissions

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