Snitz Forums 2000
Snitz Forums 2000
Home | Profile | Register | Active Topics | Members | Search | FAQ
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 Community Forums
 Code Support: ASP (Non-Forum Related)
 SELECT TOP 5 ...
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

Etymon
Advanced Member

United States
2391 Posts

Posted - 19 November 2007 :  03:31:35  Show Profile  Visit Etymon's Homepage
Just curious about something.

If I do a SQL query something like SELECT TOP 5, then how might I select the various records within that range?

For example, if the query was for the top 5 member names with the most posts and I wanted to single out just the 3rd position, how would I identify which one was the third as opposed to say, the 5th?

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 19 November 2007 :  05:41:39  Show Profile  Send ruirib a Yahoo! Message
A SELECT TOP requires an ORDER BY clause, so the third will be the 3rd record in the recordset and so on. You will need to navigate to the record position you want.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

Etymon
Advanced Member

United States
2391 Posts

Posted - 20 November 2007 :  11:27:58  Show Profile  Visit Etymon's Homepage
Could you put that into Response.Write
Go to Top of Page

ruirib
Snitz Forums Admin

Portugal
26364 Posts

Posted - 20 November 2007 :  11:39:27  Show Profile  Send ruirib a Yahoo! Message
Don't know what you mean.
Anyway, you will need to use the recorsed.movenext method twice to get to the 3rd record and then you can do whatever you want to do with the record.


Snitz 3.4 Readme | Like the support? Support Snitz too
Go to Top of Page

muzishun
Senior Member

United States
1079 Posts

Posted - 20 November 2007 :  13:48:41  Show Profile  Visit muzishun's Homepage
Etymon, to use your example, you'll be looking at something like this:


strSQL = "SELECT TOP 5 * FROM FORUM_MEMBERS ORDER BY M_POSTS DESC;"
Set rs = Server.CreateObject("ADODB.RecordSet")
rs.Open strSQL, my_Conn

rs.MoveNext
rs.MoveNext

'Now you're in the third record, so you can do whatever you want with it

rs.Close
Set rs = Nothing


This is basically what ruirib is referring to.

Bill Parrott
Senior Web Programmer, University of Kansas
Co-Owner and Code Monkey, Eternal Second Designs (www.eternalsecond.com)
Personal Website (www.chimericdream.com)
Go to Top of Page

Etymon
Advanced Member

United States
2391 Posts

Posted - 22 November 2007 :  05:31:26  Show Profile  Visit Etymon's Homepage
Thanks guys!

That helps!

Etymon
Go to Top of Page

muzishun
Senior Member

United States
1079 Posts

Posted - 22 November 2007 :  11:49:50  Show Profile  Visit muzishun's Homepage
You're welcome.

Bill Parrott
Senior Web Programmer, University of Kansas
Co-Owner and Code Monkey, Eternal Second Designs (www.eternalsecond.com)
Personal Website (www.chimericdream.com)
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Topic Locked
 Printer Friendly
Jump To:
Snitz Forums 2000 © 2000-2021 Snitz™ Communications Go To Top Of Page
This page was generated in 0.24 seconds. Powered By: Snitz Forums 2000 Version 3.4.07