Solved

Do until EOF or a specific number of times

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

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 information …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

932 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now