SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old October 29th, 2009, 12:02 PM
buck1107 buck1107 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 31 buck1107 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 6 m 2 sec
Reputation Power: 2
Question Query - General - A single query for many reports? - best practice

Hi,
I'm writing a query to hopefully return distinct results of several columns. I am needing to write 15 different reports on the same asp page, each of which based upon a different column's results of the same table. For example, report 1 will check to see if column "out1" is equal to 'n,' 'c,' or 'p'. Report 2 will check column "out2," and so on...
Multiple rows can contain the same CourseID, and 'n,' 'c,' or 'p' can occur multiple times, hence the distinct.

The table structure is:

CourseID | Out1 | Out2 [so on...to Out15]


My question is: can I write this as one query which finds distinct entries for each of the "Out..." columns and just display/filter the results through my asp coding, or will it be best to have a separate query for each report, as I've done below (for the "Out1" column)? I've tried doing a distinct with all of the Out... columns, but that doesn't work for my needs. Is there a way to somehow group each Out... column into a separate result?
Many thanks for any help!

Code:
SELECT   distinct
t.CourseID,

t.Out1,   
		  
t.Complete,  

FROM         
						
(
SELECT   
AMS_Courses.CourseID,  
AMS_ContentOverviewObjectiveOutcome.Out1,   
AMS_ContentOverview.Complete,  
                
FROM         
AMS_ContentOverviewObjectiveOutcome INNER JOIN 
 
AMS_Courses ON 

AMS_ContentOverviewObjectiveOutcome.CourseID = 

AMS_Courses.CourseID INNER JOIN 
 
AMS_ContentOverview ON AMS_Courses.CourseID = 

AMS_ContentOverview.CourseID 

WHERE 
Out1 <> 'n/a' and Out1 <> ''
)
t
;

Reply With Quote
  #2  
Old October 30th, 2009, 02:36 PM
June7 June7 is offline
Contributing User
Click here for more information.
 
Join Date: Apr 2009
Location: The Great Land
Posts: 536 June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level)June7 User rank is First Lieutenant (10000 - 20000 Reputation Level) 
Time spent in forums: 1 Week 13 h 58 m 7 sec
Reputation Power: 124
Use variables. Use a variable for the Out columns. Build the SQL in a variable. Have a loop that increments 15 times to produce each report. Something like (is this an ASP question? - I don't know the line continuation character for ASP):
Code:
For i = 1 to 15
strSQL = "SELECT distinct t.CourseID, t.Out" & i & ", t.Complete, " & _
"FROM (SELECT " & _
"AMS_Courses.CourseID, " & _
"AMS_ContentOverviewObjectiveOutcome.Out1, " & _
"AMS_ContentOverview.Complete, " & _
"FROM " & _
"AMS_ContentOverviewObjectiveOutcome INNER JOIN " & _
"AMS_Courses ON " & _
"AMS_ContentOverviewObjectiveOutcome.CourseID = " & _
"AMS_Courses.CourseID INNER JOIN " & _
"AMS_ContentOverview ON AMS_Courses.CourseID = " & _
"AMS_ContentOverview.CourseID " & _
"WHERE " & _
"Out" & i & " <> 'n/a' AND Out" & i  & "<> 't');"
'code to run report with strSQL
Next

Last edited by June7 : November 1st, 2009 at 11:30 PM.

Reply With Quote
  #3  
Old November 2nd, 2009, 02:17 PM
buck1107 buck1107 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 31 buck1107 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 6 m 2 sec
Reputation Power: 2
Many thanks! I'll give it a try.

Quote:
Originally Posted by June7
Use variables. Use a variable for the Out columns. Build the SQL in a variable. Have a loop that increments 15 times to produce each report. Something like (is this an ASP question? - I don't know the line continuation character for ASP):
Code:
For i = 1 to 15
strSQL = "SELECT distinct t.CourseID, t.Out" & i & ", t.Complete, " & _
"FROM (SELECT " & _
"AMS_Courses.CourseID, " & _
"AMS_ContentOverviewObjectiveOutcome.Out1, " & _
"AMS_ContentOverview.Complete, " & _
"FROM " & _
"AMS_ContentOverviewObjectiveOutcome INNER JOIN " & _
"AMS_Courses ON " & _
"AMS_ContentOverviewObjectiveOutcome.CourseID = " & _
"AMS_Courses.CourseID INNER JOIN " & _
"AMS_ContentOverview ON AMS_Courses.CourseID = " & _
"AMS_ContentOverview.CourseID " & _
"WHERE " & _
"Out" & i & " <> 'n/a' AND Out" & i  & "<> 't');"
'code to run report with strSQL
Next

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Query - General - A single query for many reports? - best practice


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump





 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek