<%@ LANGUAGE = VBScript %> <% 'Dr. Thomas E. Hicks - Trinity University - File DisplayUser07.asp - DISTINCT 'First Display only the Name and No of all records from table Users of the 'Security Database in ascending order by Name. No Duplicates! 'Second Display only the Name of all records from table Users of the 'Security Database in decending order by Name. No Duplicates! 'Use the Record Set approach! %> <% Option Explicit %> DisplayUser07.asp <% Dim Conn, UsersRecSet, Query 'Create a Connection Object Set Conn = Server.CreateObject ("ADODB.Connection") 'Open Security ODBC with the Connection Object Conn.Open "Security" 'Define the Query - declared as a variable because often long! Query = "SELECT DISTINCT [NAME], [NO] FROM Users ORDER BY [Name] " 'Create the Record Set Object Set UsersRecSet = Server.CreateObject ("ADODB.Recordset") 'Fill the UsersRecSet with the Results of the SQL Query - Static UsersRecSet.Open Query, Conn, adOpenStatic %>
Dual Processing of Record Set - DisplayUser07.asp
Dr. Thomas E. Hicks Trinity University

Name & No by Name ASC - No Duplicates

<% Do Until UsersRecSet.EOF %> Name : <% = UsersRecSet ("NAME") %>
No : <% = UsersRecSet ("NO") %>

<% UsersRecSet.MoveNext Loop %>
Name by Name [DESC] - No Duplicates

<% UsersRecSet.MoveLast Do Until UsersRecSet.BOF %> Name : <% = UsersRecSet ("NAME") %>
<% UsersRecSet.MovePrevious Loop ' Close the Connection. I try to close the connection asap. Conn.Close %>