Wrox Home  
Search P2P Archive for: Go

  Return to Index  

asp_databases thread: Re: How to get TOP 2-10 of records TOP 1-10 in SQL?


Message #1 by "CLINTON PARSLEY" <cparsley@m...> on Fri, 19 Apr 2002 11:16:28 -0700
Just because you get all 10 records doesnt mean you need to
display them...I used MicroSofts(c)advworks.mdb for this example.
<%
Sub getRecordSet(sSql)
  Dim strSql, arrTop, intLastRecord, objRS
  strSql = sSql
  Set objRS = Server.CreateObject("ADODB.Recordset")
  objRS.Open strSql, objConn
  arrTop = objRS.GetRows
  intLastRecord = UBound(arrTop,2)

  ' Clean up
  objRS.Close
  Set objRS = Nothing

  Response.Write("<table>")
  Response.Write("<tr>")
  Response.Write("<th>Record Number</th><th>Contact Name</th>" & _
  "<th>Contact Title</th>")
  Response.Write("</tr>")

  Dim x
  ' start your display from the 2nd element of the array
  For x = 1 to intLastRecord
    Response.Write("<tr>")
    Response.Write("<th>" & x + 1 & "</th><td>" & arrTop(0,x) & _
    "</td><td>" & arrTop(1,x) & "</td>")
    Response.Write("</tr>")
  Next
  Response.Write("</table>")
End Sub

getRecordSet("Select Top 10 ContactName,ContactTitle from Customers")
%>

hth,
Clint

::SELECT TOP 10 FROM TBLDOWNLOADS
::This is fine if im getting all the top 10 list, but what about if I
::only need the top 2 to 10?


_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com/intl.asp.

Message #2 by "Earljon K. A. Hidalgo" <earl@p...> on Fri, 19 Apr 2002 14:10:51 +0800
This is a multi-part message in MIME format.

------=_NextPart_000_021D_01C1E7AC.03093210
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

Hi to all..
Im having problem in getting records that are belong to the top 2 to 10 
and excluding the data of top 1. How can i be able to get records from 2 
to 10 if the data is changing everytime a user access it.

    SELECT TOP 10 FROM TBLDOWNLOADS

    This is fine if im getting all the top 10 list, but what about if I 
only need the top 2 to 10?

Thanks in advance!

--------
Earljon


Message #3 by "Ken Schaefer" <ken@a...> on Fri, 19 Apr 2002 16:08:16 +1000
SELECT TOP 10 Field1
FROM table1
WHERE ID NOT IN
    (
    SELECT TOP 1 Field1
    FROM table1
    )

but I would suggest that the way you are currently doing it is probably the
fastest.

Cheers
Ken

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
From: "Earljon K. A. Hidalgo" <earl@p...>
Subject: [asp_databases] How to get TOP 2-10 of records TOP 1-10 in SQL?


Hi to all..
Im having problem in getting records that are belong to the top 2 to 10 and
excluding the data of top 1. How can i be able to get records from 2 to 10
if the data is changing everytime a user access it.

    SELECT TOP 10 FROM TBLDOWNLOADS

    This is fine if im getting all the top 10 list, but what about if I only
need the top 2 to 10?


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


  Return to Index