Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Development Tools
 Reporting Services Development
 Showing all Categories in a Report

Author  Topic 

muzzettemm
Posting Yak Master

212 Posts

Posted - 2009-09-22 : 05:46:56
Hi guys i have a problem I have a table that shows a participants activity for the state. The fields are both drop down boxes One is [state category] and [state services].

under [State Category] = Academic Support, Self Concept and Counseling

and under [State Services] = "Computer Class Hours";"GED Class Hours";"College Class Hours";"Cultural Activites Hours";"Leadership Hours";"Individual - Personal Adjustment Hours";"Individual - Academic Progress Hours";"Individual - Vocational Planning Hours";"Group - Personal Adjustment Hours";"Group - Academic Progress Hours";"Group - Vocational Planning Hours"


The thing is the users only uses the Self Concept [state Category] and Cultural Activities Hours [State Services]

but for a particular report I need all of these categories to show, but in a particular order. Now I got help from all you great db gurus before on another report. I'm just not sure how to get all the Categories to show even thought there are no hours asociated with them. can someone help plse. Also does that make sense???

SELECT     AdultStateActivity_tbl.[Contact Date], AdultStateActivity_tbl.[Earned hours], Parent.[Parent First Name], Parent.[Parent Last Name], Parent.[Parent ID], 
AdultStateActivity_tbl.[State Category] AS Expr1, AdultStateActivity_tbl.[State Services] AS Expr2, COUNT(*) AS Expr3
FROM AdultStateActivity_tbl INNER JOIN
Parent ON AdultStateActivity_tbl.[Parent ID] = Parent.[Parent ID] INNER JOIN
StateLookup_tbl ON Parent.[Parent ID] = StateLookup_tbl.[Parent ID]
GROUP BY AdultStateActivity_tbl.[Contact Date], AdultStateActivity_tbl.[Earned hours], Parent.[Parent First Name], Parent.[Parent Last Name], Parent.[Parent ID],
AdultStateActivity_tbl.[State Category], AdultStateActivity_tbl.[State Services]
HAVING (StateLookup_tbl.[State Category] IN (N'Academic Support', N'Self Concept', N'Counseling')) AND (AdultStateActivity_tbl.[Contact Date] BETWEEN
@Beginning_ContactDate AND @End_ContactDate)
ORDER BY CASE WHEN AdultStateActivity_tbl.[State Category] = N'Academic Support' THEN 0 ELSE 1 END,
CASE WHEN AdultStateActivity_tbl.[State Services] = N'Computer Class Hours' THEN 0 ELSE 1 END,
CASE WHEN AdultStateActivity_tbl.[State Services] = N'GED Class Hours' THEN 0 ELSE 1 END,
CASE WHEN AdultStateActivity_tbl.[State Services] = N'College Class Hours' THEN 0 ELSE 1 END,
CASE WHEN AdultStateActivity_tbl.[State Category] = N'Self Concept' THEN 0 ELSE 1 END,
CASE WHEN AdultStateActivity_tbl.[State Services] = N'Cultural Activities Hours' THEN 0 ELSE 1 END,
CASE WHEN AdultStateActivity_tbl.[State Services] = N'Leadership Hours' THEN 0 ELSE 1 END,
CASE WHEN AdultStateActivity_tbl.[State Category] = N'Counseling' THEN 0 ELSE 1 END,
CASE WHEN AdultStateActivity_tbl.[State Services] = N'Individual - Personal Adjustment Hours' THEN 0 ELSE 1 END,
CASE WHEN AdultStateActivity_tbl.[State Services] = N'Individual - Academic Progress Hours' THEN 0 ELSE 1 END,
CASE WHEN AdultStateActivity_tbl.[State Services] = N'Individual - Vocational Planning Hours' THEN 0 ELSE 1 END,
CASE WHEN AdultStateActivity_tbl.[State Services] = N'Group - Personal Adjustment Hours' THEN 0 ELSE 1 END,
CASE WHEN AdultStateActivity_tbl.[State Services] = N'Group - Academic Progress Hours' THEN 0 ELSE 1 END,
CASE WHEN AdultStateActivity_tbl.[State Services] = N'Group - Vocational Planning Hours' THEN 0 ELSE 1 END

AjarnMark
SQL Slashing Gunting Master

3246 Posts

Posted - 2009-09-22 : 12:23:56
A coule of things to consider...

1) Displaying all values for a column regardless of whether there are matching rows is usually handled with a OUTER JOIN instead of an INNER JOIN. The way your query is structured, I'm guessing you would use a RIGHT OUTER JOIN on the last table in the FROM clause, if I'm reading this right.
2) Your code would be simpler if you could add a column to the AdultStateActivity_tbl called SortOrder and just set the values there according to the order you want the records to come out. Then, your ORDER BY just becomes ORDER BY SortOrder rather than a huge CASE statement.

--------------------------------------------
Brand yourself at EmeraldCityDomains.com
Go to Top of Page
   

- Advertisement -