Solved

Do until EOF or a specific number of times

Posted on 2004-08-09
5
1,088 Views
Last Modified: 2008-01-09
I would like to know how to do a loop in asp so that it would retrive files until the EOF OR to lets say 5.

So if there are 3 records in the db it will only retrive 3 records from the db
or if there are 10 records in the db it will only retrive 5 records from the db
0
Comment
Question by:quest_capital
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 15

Expert Comment

by:joeposter649
ID: 11756606
The best way would be to change the SQL to limit the results.  Depending on the DB you would use something like "rownum" or "top" to get the first 5 records.
0
 
LVL 3

Expert Comment

by:dwaldner
ID: 11756640
in vbscript:

while (condition here)
  (code lines)
wend

example for cycling through a recordset object (rs):

counter = 0
while not rs.eof
  counter = counter + 1
  rs.moveNext
wend
0
 
LVL 4

Expert Comment

by:tenacium
ID: 11756871
Without focusing too much on syntax, you could do something like:

Select count(*) from table

Then, set the result to a variable "x".

Select case x

Case x < 5
  y = "Select * From"
Case x > 5
  y = "Select TOP 3 From"

End Select

Then build your SQL query using the variable "y".
0
 
LVL 3

Accepted Solution

by:
hyperslug earned 125 total points
ID: 11757079
Dim MaxRecs : MaxRecs = 5

while not rs.eof and MaxRecs > 0
    ' do whatever
    MaxRecs = MaxRecs - 1
    rs.movenext
wend
0
 
LVL 15

Expert Comment

by:joeposter649
ID: 11762619
That won't "only retrive 5 records from the db".
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
alert(innerHTML); 8 45
Hide and Unhide Table 6 42
StoredProcedure to JSON query faulty syntax 2 45
Getting robots.txt Error 9 57
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question