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)
 SQL statement question
 New Topic  Topic Locked
 Printer Friendly
Author Previous Topic Topic Next Topic  

h20
Starting Member

39 Posts

Posted - 30 July 2001 :  14:09:14  Show Profile
How do I limit the amout of records returned by a query statement? For example, How would I pull only the first ten records that match a certain criteria?

Thanks in advance,
Scott

HuwR
Forum Admin

United Kingdom
20584 Posts

Posted - 30 July 2001 :  14:18:04  Show Profile  Visit HuwR's Homepage
you would use

SELECT TOP 10 item1,item2 FROM table

Go to Top of Page

h20
Starting Member

39 Posts

Posted - 30 July 2001 :  14:41:51  Show Profile
Many thanks HuwR...

Go to Top of Page

Spoon
Average Member

Ireland
507 Posts

Posted - 31 July 2001 :  07:00:57  Show Profile  Visit Spoon's Homepage  Send Spoon an ICQ Message
quote:

Many thanks HuwR...





You can this also to search:

SEARCHING A DATABASE

-----------------------
try this as an example also
====================

SEARCHTEXT is a value request from a form. ill explain the rest after



<%
Dim DATAPATH
DATPATH = "c:\path\to\database" 'path to your database

Set rsRECORDSET = Server.CreateObject("ADODB.Recordset")
Set DATABASE = Server.CreateObject("ADODB.Connection")
DATABASE.Open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & DATA_PATH & ";

SQL = "SELECT * FROM TABLE_NAME WHERE FIELD_NAME LIKE '%" & SEARCHTEXT & "%' ORDER BY FIELD_NAME ASC;"

rsRECORDSET.Open SQL, DATABASE

Dim MAXRECORDS
MAXRECORDS = 10 ' define the amount of records you want to show

Dim COUNTER
COUNTER = 1

Do while NOT rsRECORDSET.EOF AND COUNTER <= MAXRECORDS
'Now write out the html in the way you want to display your info. Example below
%>
Name: <%= rsRECORDSET("FIELD_NAME_ONE")
Phone: <%= rsRECORDSET("FIELD_NAME_TWO")
<br><br>
<%
COUNTER = COUNTER + 1
rsRECORDSET.Movenext
loop

rsRECORDSET.close
Set rsRECORDSET = NOTHING
DATABASE.close
SET DATABASE = NOTHING
%>


The SQL statement simply searchs in TABLE_NAME where the FIELD_NAME is LIKE the SEARCHTEXT. Then it ORDERs them by FIELD_NAME alphabet/// or Numerically.

The rest yout should understand. The other method might be easier, but hey

Regards - Spoon

Begineer? Need help installing the forums? - www.aslickpage.com/snitz_help.html

www.ASlickPage.com - Private Messaging
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.38 seconds. Powered By: Snitz Forums 2000 Version 3.4.07