HiI have some code that produces a report to calculate actual enrolments, continuing students, transferred, withdrawn, cancelled, completed and percentage retained which is (continuing + completed)/actual enrolments. The code works great but as usual the goalposts are shifted after signoff.The figures are based on an academic year which is fair enough but the management now want to calculate the figures based on a date also. They want it to return the numbers for the whole year and since 1st November in this academic year in the same report. This is because any withdrawals before 1st November don’t count against retention.Is it possible to force the query to return two numbers for each course based on the different dates so there would be extra columns based on the extra query that I’d need to run. One of the columns would show the year as a whole while the other column would just show the data since 01/11/2006. If I can get it to return all the columns in the first instance I can then remove what I don’t need.This is the code I have so far.SELECT TOP 100 PERCENT SD.AcademicYearID, O.Code, O.Name, O.SID, prosolution.dbo.CollegeLevel.Code AS [College Level Code], prosolution.dbo.CollegeLevel.Name AS [College Level Name], O.TargetStudents, COUNT(E.StudentDetailID) AS [Total Students], TotalEnrols = SUM(CASE WHEN E.CompletionstatusID = '1' THEN 1 ELSE 0 END) + SUM(CASE WHEN E.CompletionstatusID = '2' THEN 1 ELSE 0 END) + SUM(CASE WHEN E.CompletionstatusID = '3' THEN 1 ELSE 0 END) + SUM(CASE WHEN E.CompletionstatusID = '4' THEN 1 ELSE 0 END) + SUM(CASE WHEN E.CompletionstatusID = '7' THEN 1 ELSE 0 END), ContEnrols = COUNT(E.StudentDetailID) - SUM(CASE WHEN E.CompletionstatusID = '2' THEN 1 ELSE 0 END) - SUM(CASE WHEN E.CompletionstatusID = '3' THEN 1 ELSE 0 END) - SUM(CASE WHEN E.CompletionstatusID = '4' THEN 1 ELSE 0 END) - SUM(CASE WHEN E.CompletionstatusID = '7' THEN 1 ELSE 0 END), Completed = SUM(CASE WHEN E.CompletionstatusID = '2' THEN 1 ELSE 0 END), Withdrawn = SUM(CASE WHEN E.CompletionstatusID = '3' THEN 1 ELSE 0 END), Transferred = SUM(CASE WHEN E.CompletionstatusID = '4' THEN 1 ELSE 0 END), Cancelled = SUM(CASE WHEN E.CompletionstatusID = '7' THEN 1 ELSE 0 END), Retained = SUM(CASE WHEN E.CompletionstatusID = '1' THEN 1 ELSE 0 END) + SUM(CASE WHEN E.CompletionstatusID = '2' THEN 1 ELSE 0 END), [Percentage Retained] = CAST((CAST(SUM(CASE WHEN E.CompletionstatusID = '1' THEN 1 ELSE 0 END) AS DECIMAL(19, 2)) + CAST(SUM(CASE WHEN E.CompletionstatusID = '2' THEN 1 ELSE 0 END) AS DECIMAL(19, 2))) / NULLIF (CAST(SUM(CASE WHEN E.CompletionstatusID = '1' THEN 1 ELSE 0 END) AS DECIMAL(19, 2)) + CAST(SUM(CASE WHEN E.CompletionstatusID = '2' THEN 1 ELSE 0 END) AS DECIMAL(19, 2)) + CAST(SUM(CASE WHEN E.CompletionstatusID = '3' THEN 1 ELSE 0 END) AS DECIMAL(19, 2)) + CAST(SUM(CASE WHEN E.CompletionstatusID = '4' THEN 1 ELSE 0 END) AS DECIMAL(19, 2)) + CAST(SUM(CASE WHEN E.CompletionstatusID = '7' THEN 1 ELSE 0 END) AS DECIMAL(19, 2)), 0) * 100 AS DECIMAL(19, 2)), [CollegeLevelPercentage] = (SELECT (CAST(SUM(CASE WHEN En.CompletionstatusID = '1' THEN 1 ELSE 0 END) AS DECIMAL(19, 2)) + CAST(SUM(CASE WHEN En.CompletionstatusID = '2' THEN 1 ELSE 0 END) AS DECIMAL(19, 2))) / CAST((SUM(CASE WHEN En.CompletionstatusID = '1' THEN 1 ELSE 0 END) + SUM(CASE WHEN En.CompletionstatusID = '2' THEN 1 ELSE 0 END) + SUM(CASE WHEN En.CompletionstatusID = '3' THEN 1 ELSE 0 END) + SUM(CASE WHEN En.CompletionstatusID = '4' THEN 1 ELSE 0 END) + SUM(CASE WHEN En.CompletionstatusID = '7' THEN 1 ELSE 0 END)) AS DECIMAL(19, 2)) * 100 FROM prosolution.dbo.Enrolment En INNER JOIN prosolution.dbo.Offering Offering ON En.OfferingID = Offering.OfferingID INNER JOIN prosolution.dbo.StudentDetail StudD ON En.StudentDetailID = StudD.StudentDetailID INNER JOIN prosolution.dbo.CollegeLevel CL ON Offering.SID = CL.SID WHERE Offering.AcademicYearId = '06/07' AND CL.SID = O.SID GROUP BY CL.SID)FROM prosolution.dbo.Enrolment E INNER JOIN prosolution.dbo.Offering O ON E.OfferingID = O.OfferingID INNER JOIN prosolution.dbo.StudentDetail SD ON E.StudentDetailID = SD.StudentDetailID INNER JOIN prosolution.dbo.CollegeLevel ON O.SID = prosolution.dbo.CollegeLevel.SIDWHERE SD.AcademicYearId = '06/07'GROUP BY O.Code, O.Name, O.TargetStudents, SD.AcademicYearID, O.SID, prosolution.dbo.CollegeLevel.Code, prosolution.dbo.CollegeLevel.NameORDER BY O.Code, SD.AcademicYearID
ThanksDan