I am trying to use the With Rollup function to determine the TOTAL number of rows returned in my query and use that number to determine the percentage of each result in relation to the TOTAL rows in the query.
Here is my code:
Declare @startDate DateTime, @endDate DateTime;
Set @startDate = '01/01/01'
Set @endDate = '01/01/13'
SELECT
isnull(EducationType.EducationTypeDesc, 'UNKNOWN') as 'Education Type Description',
COUNT(isnull(EducationType.EducationTypeDesc, 'UNKNOWN')) as 'Record Count'
FROM
EducationType LEFT OUTER JOIN
Education ON EducationType.EducationTypeID = Education.EducationTypeID LEFT OUTER JOIN
Volunteer ON Volunteer.PartyID = Education.PartyID
WHERE (Volunteer.SwornDate BETWEEN @startDate AND @endDate)
GROUP BY isnull(EducationType.EducationTypeDesc, 'UNKNOWN')
WITH ROLLUP
ORDER BY isnull(EducationType.EducationTypeDesc, 'UNKNOWN')
I get the total count in the record in which EducationType.EducationTypeDesc shows NULL but cannot figure out how to calculate the percentage in the query.
Thanks
Andy
Load the row count from an un-grouped version of your query, and the calculate the percentage: