Solved

Do until EOF or a specific number of times

Posted on 2004-08-09
5
1,089 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I have helped a lot of people on EE with their coding sources and have enjoyed near about every minute of it. Sometimes it can get a little tedious but it is always a challenge and the one thing that I always say is:   The Exchange of informatio…
Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

623 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