 |
| 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
|
|
|
|

July 6th, 2004, 10:10 AM
|
|
Registered User
|
|
Join Date: Jul 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

July 6th, 2004, 11:31 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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
|
|

July 6th, 2004, 02:57 PM
|
|
Registered User
|
|
Join Date: Jul 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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?
|
|

July 6th, 2004, 03:01 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|
|

July 6th, 2004, 04:22 PM
|
|
Registered User
|
|
Join Date: Jul 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
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.
|
|

July 6th, 2004, 05:07 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
|
|
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
|
|

July 6th, 2004, 11:28 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2004
Posts: 331
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Dear Librarian, Vijay G is quite right that with out knowing the actual sitiation how one can help you ?
Love 4 all
|
|
 |