If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > how to add/append an array to an array

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-28-03, 09:31
nmd nmd is offline
Registered User
 
Join Date: Feb 2003
Posts: 15
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 ..
Reply With Quote
  #2 (permalink)  
Old 03-03-03, 09:55
Frettmaestro Frettmaestro is offline
Registered User
 
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!"
Reply With Quote
  #3 (permalink)  
Old 03-03-03, 11:23
rhs98 rhs98 is offline
Super Moderator
 
Join Date: Feb 2002
Location: Hampshire, UK
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??!
Reply With Quote
  #4 (permalink)  
Old 03-03-03, 15:21
nmd nmd is offline
Registered User
 
Join Date: Feb 2003
Posts: 15
Quote:
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
Reply With Quote
  #5 (permalink)  
Old 03-03-03, 16:05
nmd nmd is offline
Registered User
 
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...
Reply With Quote
  #6 (permalink)  
Old 03-03-03, 17:16
rhs98 rhs98 is offline
Super Moderator
 
Join Date: Feb 2002
Location: Hampshire, UK
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.
Reply With Quote
  #7 (permalink)  
Old 03-03-03, 17:18
rhs98 rhs98 is offline
Super Moderator
 
Join Date: Feb 2002
Location: Hampshire, UK
Posts: 441
Quote:
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...
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On