Forums

ASP

This topic is locked

Return Records starting with speceific character..

Posted 15 Dec 2002 02:17:34
1
has voted
15 Dec 2002 02:17:34 LiToZ LiToZ posted:
i have a page that shows all the records in a table and i want to put alphabetics from A to Z so that when the user clicks on A for example the page shows ONLY records starting with A ?

Replies

Replied 16 Dec 2002 19:03:20
16 Dec 2002 19:03:20 Dave Blohm replied:
Look at the SQL statement below:

<%
Dim rsNewsArts
Dim rsNewsArts_numRows

Set rsNewsArts = Server.CreateObject("ADODB.Recordset"
rsNewsArts.ActiveConnection = MM_WebDevSite_STRING
rsNewsArts.Source = "SELECT * FROM dbo.WD_News WHERE Headline LIKE '" & Request.QueryString("alpha" & "%' ORDER BY id DESC"
rsNewsArts.CursorType = 0
rsNewsArts.CursorLocation = 2
rsNewsArts.LockType = 1
rsNewsArts.Open()

%>

This assumes you're passing the variable ALPHA to this page (which will be the character you are sorting on), hence the request.querystring in the middle of the SQL statement.

you can change your SQL statement as follows to suit your needs:

LIKE '%varStrning%' --- says find me anything with varString ANYWHERE in the text

LIKE '%varString' --- says find me anything with varString at the end of the text

and of course, the example above says find me anything that begins with your variable.

hope this helps...

Doc
Rangewalk Digital Studios

Reply to this topic