Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP 3 Classic ASP Active Server Pages 3.0 > Classic ASP Basics
|
Classic ASP Basics For beginner programmers starting with "classic" ASP 3, pre-".NET." NOT for ASP.NET 1.0, 1.1, or 2.0
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 15th, 2003, 07:07 AM
Registered User
 
Join Date: Aug 2003
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default effectively show only one value from a table where

I would like to know how to effectively only display one value from a table if multiple identical values exist. The following is an explanation of my program and its code:

In the database used for this program there are many numerical values for CategoryA in Table1 (variables CategoryA and Table1, respectively). Also in Table1 are many numerical values for CategoryB (variable categoryB). The values in categoryB are also held in Table2 as well as their 2 names, variables name1 and name2. This code gets the CategoryA value through a query string and selects only those values. Then it looks at the values remaining in CategoryB that link up with CategoryA after CategoryA has been limited to only 1 value. The same values in CategoryB are then found in Table2 and there two names are returned (name1 and name2). The key to this code is that although there may be many values in CategoryB that are the same each name is only output once so an identical name is not displayed to the user. Everything works ok; each name is only displayed once but, at the end of the code I get the following error:
error '80020009'
Exception occurred.
/code.asp,
line xx (see code for line)
Could someone please look through this code and write a possible solution to this error or tell me a more effective way to display name1 and name2 only once. Your help is greatly appreciated. I am afraid that my beginning ASP skills have failed me.

'database connection
DIM db
set db= server.createobject("ADODB.Connection")
db.open "database", adOpenForwardOnly, adCmdTable

'Get the value that will be filtered for CategoryA from Table1
Dim CategoryA
CategoryA = Request.QueryString("CategoryA")

'Select only the one value from CategoryA and open connection
Dim SQL, SQL2
Sql = "SELECT * FROM Table1 WHERE CategoryA = '" & CategoryA & "' ORDER BY CategoryB DESC;"
Dim rsVar1
set rsVar1 = Server.createObject("ADODB.Recordset")
rsReview.open mySQL, db2

'The following lines of code go to Table2 and find the corresponding values of CategoryB with that of Table1 CategoryB and writes out the 2 names.
DO WHILE NOT rsReview.EOF
CategoryB = rsVar1("CategoryB")
Sql2 = "SELECT * FROM Table2 WHERE CategoryB = '" & CategoryB & "' ORDER BY Name1 DESC;"
Dim rsVar2
set rsVar2 = Server.createObject("ADODB.Recordset")
rsCourse.open SQL2, db
response.write rsVar2("Name1")
response.write rsVar2("Name2")
rsVar1.MoveNext

'This is the key to the program, the following makes sure that identical values are not shown or else it will skip to the next record
IF rsVar1("CategoryB") = CategoryB THEN
'The next line is where the error occurs
DO WHILE NOT rsReview("CategoryB") <> CategoryB
rsVar1.MoveNext
LOOP
ELSE
END IF
LOOP
 
Old August 15th, 2003, 07:37 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

I think the SQL keyword DISTINCT is what you are looking for:

Code:
Sql2 = "SELECT DISTINCT Name1, Name2 FROM Table2 WHERE CategoryB = '" & CategoryB & "' ORDER BY Name1 DESC;"
Quote from BOL:
DISTINCT

Specifies that only unique rows can appear in the result set. Null values are considered equal for the purposes of the DISTINCT keyword.


Btw: You should NEVER do SELECT * - always name the columns you want!






Similar Threads
Thread Thread Starter Forum Replies Last Post
Moving 2,00,000 records effectively FileFound Visual Studio 2005 9 September 21st, 2007 08:20 AM
Hide/show rows in a table smi13y XSLT 6 December 28th, 2006 08:48 PM
Show ALL records from one table janise MySQL 1 September 1st, 2005 06:08 PM
Doesn't show all records from a table janise Access 10 July 27th, 2005 04:19 AM
Show table in DataList miguel.ossa ASP.NET 1.0 and 1.1 Basics 1 February 26th, 2004 10:29 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.