473,405 Members | 2,294 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Running SQL query for each item in an Array

26
I am trying to run an SQL query for each item in an Array using ASP.

I have coded it as such. IDsArray() is an array of integers.

Expand|Select|Wrap|Line Numbers
  1. ArrayLength=15
  2.  
  3. sqlGetiIDs = "SELECT * FROM Table1 WHERE (dID = " & IDsArray(j) & ")"
  4. j=0
  5. Dim GetiIDsRSArray(ArrayLength)
  6.  
  7. do
  8.     set GetiIDsRSArray(j) = conn.execute(sqlGetiIDs)
  9.     j=j+1
  10. loop until j=ArrayLength
  11.  
First, I get an error while declaring the array: "Expected integer constant." Why doesn't it see the variable as an integer, and how can I fix it?
Second, this seems extremely awkward to create this array of recordsets. Can anyone suggest a better methodology? I would rather have it saved into one large recordset.

Many Thanks.
Jun 28 '07 #1
2 2870
liz0001
26
I got it - I was trying to do it the hard way.

The right way to do this is from the back end, the actual database.

I created a UNION and made the array part of an actual table. Then I could run querys on it as normal and I would have access to all the data points at the same time.

I don't need it anymore, but just curious - I still don't know why the array declaration wouldn't take the variable, do anyone know about that?
Jun 29 '07 #2
jhardman
3,406 Expert 2GB
I am trying to run an SQL query for each item in an Array using ASP.

I have coded it as such. IDsArray() is an array of integers.

Expand|Select|Wrap|Line Numbers
  1. ArrayLength=15
  2.  
  3. sqlGetiIDs = "SELECT * FROM Table1 WHERE (dID = " & IDsArray(j) & ")"
  4. j=0
  5. Dim GetiIDsRSArray(ArrayLength)
  6.  
  7. do
  8.     set GetiIDsRSArray(j) = conn.execute(sqlGetiIDs)
  9.     j=j+1
  10. loop until j=ArrayLength
  11.  
First, I get an error while declaring the array: "Expected integer constant." Why doesn't it see the variable as an integer, and how can I fix it?
Second, this seems extremely awkward to create this array of recordsets. Can anyone suggest a better methodology? I would rather have it saved into one large recordset.

Many Thanks.
first, I noticed this problem before as well, I think vbscript might need a constant, rather than a variable, to define arrays. don't ask me why, it works everywhere else.

second, try:
Expand|Select|Wrap|Line Numbers
  1. 'just to simplify a little bit, let's take out the parenthases which 
  2. 'are not necessary in such a straight-forward query statement
  3. 'and let's put the conditions in a series of OR clauses
  4. sqlGetiIDs = "SELECT * FROM Table1 WHERE "
  5. for j = 0 to 15
  6.    sqlGetiIDs = sqlGetiIDs & "dID = " & IDsArray(j) & " OR "
  7. next
  8.  
  9. 'sqlGetiIDs currently ends with " OR " which needs to be removed thus:
  10. sqlGetiIDs = left(sqlGetiIDs, len(sqlGetiIDs)-4)
  11.  
  12. 'it's a good idea to check the final string just to make sure it looks right:
  13. response.write "<!-- sqlGetiIDs: " & sqlGetiIDs & " -->" & vbNewLine
  14.  
  15. 'then send this to your recordset object:
  16. objRS.open sqlGetiIDs, conn
  17. 'I just like to say "open" rather than "execute", your call, really.
Does this make sense?

Jared
Jun 29 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Bob Bedford | last post by:
I've a query quite important to execute. I've to fill an array with all result, so the query is called once wich returns all ID's Then I call the same query a second time as I shown only 10...
7
by: Christopher Brandsdal | last post by:
Hi! I have a problem running my code on 2000 server and iis5.0. The code runs perfectly on my localhost (xp iis5.1) but when i run it on 2000 server iis5.0 I get this error: ...
4
by: Orion | last post by:
Hi, This is kind of last minute, I have a day and a half left to figure this out. I'm working on a project using ms-sqlserver. We are creating a ticket sales system, as part of the system, I...
4
by: deko | last post by:
I'm a little nervous about slamming my database with a dozen Update queries in a loop that all modify RecordSources of open forms. Will the use of DoEvents and/or a Sleep function ameliorate any...
6
by: KashMarsh | last post by:
Trying to show running totals on a report, except it needs to show one total amount and values being subtracted from it. For example, the report shows a Total Inventory amount (TotInvAmt). And...
3
by: Wired Hosting News | last post by:
Lets say I have 10 products in 10 different stores and every week I get a report from each store telling me how many items they have left for each of the 10 products. So each week I enter in 100...
5
by: Wired Hosting News | last post by:
I tried to be breif and give a scenario so as not to be overlooked because it was soooo long. Let me give you real world. I am a manufacturer of goods and produce 11 items that are distributed...
2
by: Flic | last post by:
Hi, I have a basic db that I access with MySQL query browser. Everything seems fine to me but I am using this db as part of a php shopping basket and when I try to add an item I get: Notice:...
4
by: zion4ever | last post by:
Hello good people, Please bear with me as this is my first post and I am relative new to ASP. I do have VB6 experience. I have a form which enables users within our company to do an intranet...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.