Author |
Topic |
Alfred
Senior Member
USA
1527 Posts |
Posted - 25 October 2003 : 21:24:08
|
In the following statement I select all new members of the last 30 days: quote: set my_Conn = Server.CreateObject("ADODB.Connection") my_Conn.Open strConnString
strSql = "SELECT * FROM FORUM_MEMBERS WHERE M_Date > " & DateAdd("d",-30,Now()) & " ORDER BY MEMBER_ID DESC" set myMEMBERS = my_Conn.Execute(strSql)
I use a loop to display their data quote: do while not myMembers.eof response.write myMembers("M_NAME") myMembers.movenext loop
How can I specify that I want to have X records (or loops)? |
Alfred The Battle Group CREDO
|
|
The Impact
Junior Member
Australia
398 Posts |
Posted - 25 October 2003 : 21:38:12
|
Try something like that, remember that you'll need to define I as a variable.do while not myMembers.eof
for I = 1 to X
response.write myMembers("M_NAME")
myMembers.movenext
next
loop Replace the X with how many records you want. |
|
|
Alfred
Senior Member
USA
1527 Posts |
Posted - 25 October 2003 : 22:10:46
|
So, this will do ten loops only? quote: do while not myMembers.eof for I = 1 to 10 response.write myMembers("M_NAME") myMembers.movenext next loop
|
Alfred The Battle Group CREDO
|
|
|
The Impact
Junior Member
Australia
398 Posts |
Posted - 25 October 2003 : 23:44:36
|
Yes, that's what I use to limit records. |
|
|
dayve
Forum Moderator
USA
5820 Posts |
Posted - 25 October 2003 : 23:46:44
|
quote: Originally posted by Alfred
So, this will do ten loops only? quote: do while not myMembers.eof for I = 1 to 10 response.write myMembers("M_NAME") myMembers.movenext next loop
yes, but you should always include a EOF check in case there are less than 10 records. this would actually be a safer loop:
While (Not myMembers.EOF And myMembersIndex < 10)
response.write myMembers("M_NAME")
myMembersIndex = myMembersIndex+1
myMembers.movenext
Wend
You can do similar loops with Do While and For Next |
|
|
|
Alfred
Senior Member
USA
1527 Posts |
Posted - 26 October 2003 : 00:36:17
|
Thank you, gentlemen - it works wonderfully! |
Alfred The Battle Group CREDO
|
|
|
dayve
Forum Moderator
USA
5820 Posts |
Posted - 26 October 2003 : 00:52:28
|
quote: Originally posted by Alfred
Thank you, gentlemen - it works wonderfully!
I just realized the other loop method shown in this thread did in fact have an EOF check. I am just used to seeing the conditional checks done in one line. |
|
|
|
DavidRhodes
Senior Member
United Kingdom
1222 Posts |
Posted - 26 October 2003 : 07:01:40
|
Another way to do this is to use the TopSQL function, where NumberOfRecords is the amount you wish to return
strSql = "SELECT * FROM FORUM_MEMBERS WHERE M_Date > " & DateAdd("d",-30,Now()) & " ORDER BY MEMBER_ID DESC"
Set myMEMBERS = my_conn.Execute(TopSQL(strSql, NumberOfRecords)) |
The UK MkIVs Forum |
|
|
laser
Advanced Member
Australia
3859 Posts |
Posted - 26 October 2003 : 07:21:50
|
I think you missed something David |
|
|
chad
New Member
50 Posts |
Posted - 26 October 2003 : 13:11:39
|
I could be mistaken here but:
can't you just say SELECT TOP 10 FROM ..... |
|
|
redbrad0
Advanced Member
USA
3725 Posts |
|
DavidRhodes
Senior Member
United Kingdom
1222 Posts |
Posted - 26 October 2003 : 14:16:59
|
quote: Originally posted by laser
I think you missed something David
What was that |
The UK MkIVs Forum |
|
|
dayve
Forum Moderator
USA
5820 Posts |
Posted - 26 October 2003 : 14:35:50
|
quote: Originally posted by DavidRhodes
quote: Originally posted by laser
I think you missed something David
What was that
I think because you put a * instead of a number??
chad is also right, but you should still check for EOF. |
|
|
|
DavidRhodes
Senior Member
United Kingdom
1222 Posts |
Posted - 26 October 2003 : 14:46:30
|
SELECT * means select all records. SELECT TOP 10 is T-SQL isn't it? So it will only work on SQL Server (or am I wrong!). The TopSQL function is part of the snitz base code and will work on all databases |
The UK MkIVs Forum |
|
|
Nikkol
Forum Moderator
USA
6907 Posts |
|
Alfred
Senior Member
USA
1527 Posts |
Posted - 26 October 2003 : 23:13:49
|
Wow - watching the experts didcuss finer points is highly educational. And wow - I actually KNEW one of those points (the '*' standing for all fields)! |
Alfred The Battle Group CREDO
|
|
|
Topic |
|