getrows question - how to split getrows array into individual arrays?

Sorry if this is a dumb question but I can't figure out how to get the results of a database query into separate arrays.  I'm using getrows to create a 2 D array consisting of divisionID and divisionName.  But I can't figure out how to make an array of only the divisionID records and another of only the divisionName records.  I use getrows all the time to retrieve records from a db but never have had to re-assigned those records to separate arrays.   I need the names and ids in separate arrays for use with a javascript function.

Thanks for the help
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Okay, so you can do something like this:

Dim my2dResultsArray
Dim myIDArray
Dim myNameArray
Dim i
my2dResultsArray = rs.getRows()
'' set the upper bound of the two, one-dimensional target arrays to the upper bound of the results array
redim myIDArray(ubound(my2dResultsArray ,2))
redim myNameArray(ubound(my2dResultsArray ,2))
''assuming that the ID's are the 0th element, and the names are the 1st element, loop through the array and make two new arrays:
For i = 0 to ubound(my2dResultsArray,2)
  myIDArray(i) = my2dResultsArray(0,i)
  myNameArray(i) = my2dResultsArray(1,i)

'Now, take a look at the array contents:
for i=0 to ubound(myIDArray)
  response.write "myIDArray("& i &"): " &myIDArray(i) & "<BR>"

for i=0 to ubound(myNameArray)
  response.write "myNameArray("& i &"): " &myNameArray(i) & "<BR>"

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Big MontySenior Web Developer / CEO of Commented:
if divisionID and divisionNAME are in the same recordset, then using getrows will put them in the same array. theres no way to split them using getrows. you could create a loop to put the data into seperate arrays:

dim arr1()
dim arr2() "select divisionID, divisionName from someTable", objConn

counter = 0
do while not rs.EOF
   arr1(counter) = rs("divisionID")
   arr2(counter) = rs("divisionName")
   counter = counter + 1

set rs = nothing

Basically, my previous post takes the 2d array and separates the values into two single dimension arrays.

So, if you have this:


     0 (ID Element)    1 (NameElement)
0  "2"                      "Division A"
1  "4"                      "Division D"
2  "7"                      "Division Q"
3  "11"                    "Division R"
4  "16"                    "Division ZZ"
5  "20"                    "Division E"
6  "32"                    "Division F"

So, the 2d results array has the following characteristics:
-- ID is the 0th element
-- division name is the 1st element
-- ubound(my2dResultsArray,2) = 6

Now, the code re-dimensions two single dimension arrays to the upper bound of the second dimension of the results array (one for the names and one for the IDs) and then populates the two single dimension arrays as follows:

0  "2"
1  "4"
2  "7"
3  "11"
4  "16"
5  "20"
6  "32"

0  "Division A"
1  "Division D"
2  "Division Q"
3  "Division R"
4  "Division ZZ"
5  "Division E"
6  "Division F"

Hope this helps!!

saabStoryAuthor Commented:
Thanks peh803 - that works.  In fact, it looks just like what I was doing but I was getting a type mismatch when I was trying to create the singleton arrays.  I'll be comparing to see where I went off track.  Thanks for the help.
Glad I could help!

It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.