Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. 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 Databases 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
  #1 (permalink)  
Old July 6th, 2004, 10:10 AM
Registered User
 
Join Date: Jul 2004
Location: Milwaukee, WI, .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Display results from multiple tables

I have a database ("comparison") with multiple tables (total 9). The database contains survey results data from 100+ cities. All tables have one field in common ("ChartID"). I have one page displaying all the cities from the tblGeneral table. Using the ChartID as the common field from this display, users can select the city which will link them to another page which will show the detail responses for that city. On the details page I am not able to open more than one table at a time. I need to open ALL tables so I can display ALL data. I have tried the JOIN command, but cannot get it to work. Following is the code:

Code:
<%
dim ChartID
ChartID = request.querystring("ChartID")

If ChartID = "" then
    response.redirect "Results.asp"
Else
    sql = "Select * from tblGeneral WHERE ChartID=" & ChartID
    Set objRS = Server.CreateObject("ADODB.Recordset")
    objRS.Open sql, objConn

    If objRS.EOF then
        response.redirect "Results.asp"
    Else
        dim Facility, City, State
        dim LibFTE
        Facility = objRS("Facility")
        City = objRS("City")
        State = objRS("State")

        tblStaff.LibFTE = objRS("tblStaff.LibFTE")        

        objRS.Close
        Set objRS = Nothing

        objConn.Close
        Set objConn = Nothing

%>
Any help will be appreciated.
  #2 (permalink)  
Old July 6th, 2004, 11:31 AM
Friend of Wrox
 
Join Date: Jun 2003
Location: Harrisburg, PA, USA.
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Hello,

you need to union the results. I'm going to use a generic sql statement of Table1, Table2, and Table3, because I don't know all your names. For example also each has Column1, Column2, and Column3 in them:

select Column1, Column2, Column3 from Table1
where ChartID = 1
union
select Column1, Column2, Column3 from Table2
where ChartID = 1
union
-- For this example, i'm showing what to do in cases where there is no 3rd field
select Column1, Column2, NULL from Table3
where ChartID = 1

The union statement groups them together. It is important to note that all queries must have the same number of fields returned. In addition, if you want to alias the column names (select Column1 As FirstColumn, ...) then you must do it at the first query only. The names of the fields in the other queries are ignored.

Brian
  #3 (permalink)  
Old July 6th, 2004, 02:57 PM
Registered User
 
Join Date: Jul 2004
Location: Milwaukee, WI, .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

One of my tables has 16 fields. There are also several tables which have multiple entries for the same ChartID. Is there a way to send a zip file of the DB and code?
  #4 (permalink)  
Old July 6th, 2004, 03:01 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

If Brian's post has not answered your requirement, can you explain more on what you are trying to accomplish, so as to help you better.

Cheers!

_________________________
- Vijay G
Strive for Perfection
  #5 (permalink)  
Old July 6th, 2004, 04:22 PM
Registered User
 
Join Date: Jul 2004
Location: Milwaukee, WI, .
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I created an online survey. Data was submitted to an ACCESS database consisting of 9 tables. All tables are linked together by a field called ChartID. Three of the survey questions allowed multiple responses. The data to these multiple response questions each went into its own table. The other tables have fields which vary from 11 fields to 24 fields. I have created a page which will list all the submissions by city. From this list I want to use the ChartID corresponding to the city and allow the user to open a new page which will list ALL the responses to the survey questions. I can open one of the tables and display the results from that table with no problem. I am having a problem opening the subsequent tables to create a display of all the data from all the tables on the same page.
  #6 (permalink)  
Old July 6th, 2004, 05:07 PM
Friend of Wrox
 
Join Date: Jun 2003
Location: Bangalore, KA, India.
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Without knowing what the tables contain and how they are related, I am not sure how to help you out. With this little details, I am really out of thoughts to understand what you are trying to do.

What are the tables you are trying to display data from? What does tblGeneral contain? how are the data from other tables related to this? what does CHARTID mean or refer to?

If the data that you are trying to access from other tables related to the CHARTID are to be displayed separately one after the other, you can still display them by creating another SQL select to those tables, another recordset, another while loop, etc...

I am not sure if this is what you are looking for.
Cheers!

_________________________
- Vijay G
Strive for Perfection
  #7 (permalink)  
Old July 6th, 2004, 11:28 PM
Friend of Wrox
Points: 1,288, Level: 14
Points: 1,288, Level: 14 Points: 1,288, Level: 14 Points: 1,288, Level: 14
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2004
Location: Stockholm, Sweden
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to qazi_nomi
Default

Dear Librarian, Vijay G is quite right that with out knowing the actual sitiation how one can help you ?


Love 4 all


Similar Threads
Thread Thread Starter Forum Replies Last Post
display results carswelljr ASP.NET 2.0 Basics 1 April 19th, 2007 09:46 AM
Listing results from joined tables henry-horse Classic ASP Basics 5 March 9th, 2007 07:08 AM
Display results from a database on multiple pages osemollie PHP How-To 1 January 27th, 2006 07:58 AM
Multiple Tables Display in XSL bmagadi XSLT 1 February 8th, 2005 03:06 PM
Mysql Sorting results from multiple tables dcb22 SQL Language 8 October 25th, 2004 10:57 AM





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