Query help show all from table

vendredi 24 avril 2015

Hi

I have a query:

Code:

SELECT    TOP (100) PERCENT CONVERT(char(3), dbo.tblCourses.CourseDate, 0) AS Month, YEAR(dbo.tblCourses.CourseDate) AS Year, gp.OrganisationCode, gp.Name,
                      gp.Address1, gp.Address2, SUM(CASE WHEN a.AttendanceStatus IN (9) THEN 1 ELSE 0 END) AS Attended, SUM(CASE WHEN a.AttendanceStatus IN (3)
                      THEN 1 ELSE 0 END) AS [Did not attend], SUM(CASE WHEN a.AttendanceStatus IN (7) THEN 1 ELSE 0 END) AS Cancelled, gp.CCGRegion
FROM        dbo.tblGP_Practices AS gp INNER JOIN
                      dbo.tblGP_PatientLink AS pl ON gp.GPPracticeID = pl.GPPracticeID INNER JOIN
                      dbo.tblPatient AS p ON pl.PatientID = p.PatientID INNER JOIN
                      dbo.tblAppointments AS a ON p.PatientID = a.PatientID INNER JOIN
                      dbo.tblCourses ON a.CourseID = dbo.tblCourses.Course_ID
WHERE    (a.AttendanceStatus IN (1, 2, 3, 4, 6, 7, 8, 9, 10)) AND (a.AttendanceStatus IS NOT NULL)
GROUP BY gp.OrganisationCode, gp.Name, gp.Address1, gp.Address2, gp.CCGRegion, YEAR(dbo.tblCourses.CourseDate), CONVERT(char(3), dbo.tblCourses.CourseDate, 0)
HAVING      (gp.CCGRegion = N'city ccg')
ORDER BY gp.OrganisationCode

this returns the correct results but I want to be able to see all OrganisationCode from table gp (so basically all gp practices) even if they have 0 Attended, DNA or cancelled. the current query just limits it down and shows be only those with a CourseDate and value for Attended, Did not attend or cancelled.

any help would be appreciated

thanks
Query help show all from table

0 commentaires:

Enregistrer un commentaire

Labels