473,698 Members | 2,080 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 2879
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
2656
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
6920
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
2938
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
2199
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
3523
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
3192
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
4585
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
8672
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
8860
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7712
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5860
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();...
0
4361
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4614
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3038
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
2323
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1998
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.