Solved

Do until EOF or a specific number of times

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Import csv files to MS SQL 5 85
Writing comments on <p></P> or paragraph 2 19
edit .asp files 5 32
Weighted Randomizing 6 30
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…
I would like to start this tip/trick by saying Thank You, to all who said that this could not be done, as it forced me to make sure that it could be accomplished. :) To start, I want to make sure everyone understands the importance of utilizing p…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

821 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