473,722 Members | 2,240 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Running SQL query for each item in an Array

26 New Member
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 2882
liz0001
26 New Member
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 Recognized Expert Specialist
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
1708
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 results in my page. How can I avoid to call the query twice ?
7
2224
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: -------------------------------------- operation must use an updateable query
4
2657
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 need to be able to do a search for specific tickets withing price ranges, different locations within the theaters, etc. etc. My problem is in the search one of the criteria is to search for a group of seats together. For example let's say...
4
6921
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 risk involved in doing this? Should I include a Requery in the loop after executing each query? For example: For each varQry in Array("qryDeleteOldTransactions", _ "qryDeleteClient Acct", etc., etc.) db.Execute varQry
6
2939
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 then amounts for each month for the orders like JanAmt, FebAmt, etc. I want to show under each month column the following: (TotInvAmt)-(JanAmt)=B ----result shows under the Jan column B-(FebAmt)=C ---------result shows under the Feb column...
3
2201
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 records with a store number, item number, on hand qty, and date of report into my sales data table. My tables primary is a combo of store# & Item number & Date After 10 week of this I have 1000 record total with ten unique dates.
5
3528
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 to 1800 stores of a national home improvement chain store. Every week I electronicaly receive an excel spreadsheet "inventory report" with 19,800 rows or records, which I import into my tblSalesData table. The table now has 10 weeks of data or...
2
3195
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: Query failed: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '>function.extract]: First argument should be an array in functions.inc.php on line 31
4
4586
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 reservation of available resources (laptops, beamers, etc). The MySql database queries are already in place, as is the ASP administration panel. The frontend that users will see however, still needs some work. I'm really close, but since I'm no...
0
8863
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8739
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9384
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9238
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9157
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6681
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5995
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3207
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2602
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.