Avatar of dcass
dcassFlag for United States of America

asked on 

add to multidimensional array

I need to add one array to another (or add them both to a new one, but MSDN says redim is not needed but I get an error when I try to add to the next available index.
I tried dim and redim - still error - subscript out of range on arrResultsx(x,ctrx).  I also tried without the internal x loop.
SQL = "SELECT * FROM T1News where ..."
      SQL_Rs.open SQL,SQL_Cn,3
       	IF NOT(SQL_Rs.EOF) THEN
			arrResultsx = SQL_Rs.getrows
		    ctrx = ubound(arrResultsx,2)
		END IF
      	SQL_Rs.close
ctrx2=0
      SQL = "SELECT * FROM T1News where ..."
      SQL_Rs.open SQL,SQL_Cn,3
       	IF NOT(SQL_Rs.EOF) THEN
			arrResultsx2 = SQL_Rs.getrows
		    ctrx2 = ubound(arrResultsx2,2)
		END IF
      	SQL_Rs.close
      	
    ctrx = ctrx + 1
'    ctr = ctrx+ctrx2
'    ReDim arrResultsx(ctr)
'    %><%=arrResultsx(x,ctr)%><Br><%
    if ctrx2 > 0 then      ' if anything in 2nd array, then proceed
      for i = 0 to ctrx2
        for x = 0 to 30
'          redim preserve arrResultsx(x,ctrx)
          arrResultsx(x,ctrx) = arrResultsx2(x,i) ' also tried arrResultsx(ctrx)=arrResultsx2(i)
          ctrx = ctrx + 1
        next
      next
    end if

Open in new window

ASPVB ScriptMicrosoft SQL Server

Avatar of undefined
Last Comment
dcass
Avatar of Om Prakash
Om Prakash
Flag of India image

If the tables are same then why don't you combine both the sql statement using joins/union and loop through single recordset?
ASKER CERTIFIED SOLUTION
Avatar of dcass
dcass
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Anthony Perkins
>>but I get an error when I try to add to the next available index.<<
From MSDN:

Preserve
Preserves the data in an existing array when you change the size of the last dimension.
Incidentally looping like that has to be a dog performance-wise.  Not to mention the fact you have to maintain that mess of a code.

You really need to look into the Recordset method GetRows, this will load a resultset into an array directly.
Avatar of dcass
dcass
Flag of United States of America image

ASKER

Solution for defining multidimensional variable array and loading and adding to an array!
Microsoft SQL Server
Microsoft SQL Server

Microsoft SQL Server is a suite of relational database management system (RDBMS) products providing multi-user database access functionality.SQL Server is available in multiple versions, typically identified by release year, and versions are subdivided into editions to distinguish between product functionality. Component services include integration (SSIS), reporting (SSRS), analysis (SSAS), data quality, master data, T-SQL and performance tuning.

171K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo