473,387 Members | 1,575 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,387 software developers and data experts.

multiple loops with different conditions whilst querying sql table

120 100+
im trying to figure out a way to query sql table several times within the same asp statement. as opposed to opening a new asp statement each time to query sql table again & again etc

so this is what I want to do in theory

do while ID 1-6
do something / perform loop

do while ID 7-12
do something / perform loop

at the moment I can only query table and loop all records and im not sure how to set multiple loops
Expand|Select|Wrap|Line Numbers
  1. <%
  2. DIM objConn
  3. Set objConn = my conn string goes here
  4. objConn.Open
  5.  
  6. DIM ZUIDERDAM2011
  7. ZUIDERDAM2011 = "SELECT * From UK_Cruise_Holland_And_America_Zuiderdam_2011 WHERE ID IN (1,2,3,4,5,6)"
  8.  
  9. DIM objRS
  10. Set objRS = Server.CreateObject("ADODB.Recordset")
  11. objRS.Open ZUIDERDAM2011, objConn
  12.  
  13. If objRS.Eof Then 
  14. Response.write "<div align='center'>Sorry there are no current records.</div>" 
  15. Else 
  16.  
  17. Response.write "<table align=""center"" id=""Cruiseprices"" cellpadding=""0"" cellspacing=""0"">"
  18. Response.write "<tr><td class=""empty"">&nbsp;</td>"
  19. Response.write "<td class=""header"">Sail Date >> </td>"
  20. Response.write "<td class=""header"">14 May &amp;<br />21 May</td>"
  21. Response.write "<td class=""header"">28 May</td>"
  22. Response.write "<td class=""header"">4 Jun</td>"
  23. Response.write "<td class=""header"">11 Jun</td>"
  24. Response.write "<td class=""header"">18Jun, 25Jun,<br />02Jul, 09Jul,<br />16Jul, 23Jul,<br />30Jul, 06Aug</td></tr>"
  25. Response.write "<tr><td class=""empty"">&nbsp;</td>"
  26. Response.write "<td class=""titles"">Cabin</td>"
  27. Response.write "<td class=""titles"">Twin</td>"
  28. Response.write "<td class=""titles"">Twin</td>"
  29. Response.write "<td class=""titles"">Twin</td>"
  30. Response.write "<td class=""titles"">Twin</td>"
  31. Response.write "<td class=""titles"">Twin</td></tr>"
  32. Response.Write "<tr><td rowspan=""6"" class=""header"">Inside<br /><br />Stateroom</td>"
  33.  
  34. Do while not objRS.Eof 
  35.  
  36. Response.Write "<td class=""titles"">" & objRS("Cabin_Category") & "</td>"
  37. Response.Write "<td>&pound;" & objRS("Price_Band_1") & "</td>"
  38. Response.Write "<td>&pound;" & objRS("Price_Band_2") & "</td>"
  39. Response.Write "<td>&pound;" & objRS("Price_Band_3") & "</td>"
  40. Response.Write "<td>&pound;" & objRS("Price_Band_4") & "</td>"
  41. Response.Write "<td>&pound;" & objRS("Price_Band_5") & "</td></tr>"
  42.  
  43. objRS.movenext
  44.  
  45. Loop 
  46. end if 
  47.  
  48. Response.Write "</table>" & vbCrLf
  49.  
  50. objRS.Close
  51. Set objRS = Nothing
  52. objConn.Close
  53. Set objConn = Nothing
  54. %>
  55.  
thanks in advance
omar.
Jun 23 '10 #1
3 2859
Why do you need loop if you may use "if" inside of your loop:

if ID<7 then
do something
else
do something
end if
Jun 24 '10 #2
omar999
120 100+
thanks for the reply. iv actually found a better way of doing this using via a for loop

Expand|Select|Wrap|Line Numbers
  1. for x = 1 to 6
  2.   'do something
  3.    objRS.movenext
  4. next
  5.  
  6. for x = 7 to 10
  7.   'do something
  8.    objRS.movenext
  9. next
  10.  
and so on

omar.
Jun 25 '10 #3
Could be this way, but in this case, do not forget to check in the loop for the end of the record, otherwise objRS.movenext command will crash your program.

Keep in mind that this is more lines of code.
Jun 25 '10 #4

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

Similar topics

7
by: Rick Caborn | last post by:
Does anyone know of a way to execute sql code from a dynamically built text field? Before beginning, let me state that I know this db architecture is built solely for frustration and I hope to...
5
by: Tank | last post by:
I have had this post up here when i was trying to figure out how to make leading zeros and have been able to fudge that to work. I am now have trouble getting the loop that makes the folders to...
0
by: steve | last post by:
Hi all, Come across a situation I cannot figure how to work out. Im relatively new to access but have looked around and tried everything to my knowledge. I've developed an application whereby...
1
by: mjf | last post by:
Hello, We have seen up to 11 db2fm processes running at the same time, which was consuming 100% of CPU. We could not run anything else on the machine because of this. We have only one DB2...
3
by: jason.teen | last post by:
Hi, I have a table such as below and I want to write a query which says "For each product, Exclude all Rows where Rate is 0 and Code is not D, but if any of the rows for that product is found...
1
by: davidevan | last post by:
I'm trying to update a single field in a table according to the an age category as a condition. The meat of the code that executes looks like this (I created a record set, and loop through it...
3
by: dinox | last post by:
hello, i tried searching for something similar to my situation but i haven't found so far.. for example ... i have users table with 15 registered users and i want to show only 5 of them in front...
11
by: O.B. | last post by:
Does C# support anything like PHP's break command that optionally accepts a parameter specifying how many loops to break out of?
14
by: Supermansteel | last post by:
My team at work uses Cognos to run multiple queries to pull in data. Then they take that data and import into Access and then usually run an Append Query to run a RND function to pull out a few...
2
by: dechen | last post by:
I have an input in the form (as given below) in a text file. I have to loop through the contents in between two '$-$-$-$' characters. This is done by splitting at '$-$-$-$'. To get the Output as...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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...

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.