Hi. I have a query that needs to pull all locations that have one score in a specific month/year (this combo will change monthly). (Some locations have multiple scores.) I thought a DISTINCT would do it but the results are the same as without the DISTINCT. I hope someone can assist. Thanks in advance.
Code:
SELECT DISTINCT dbo.PracticeTable.OPNumber AS [Practice ID], dbo.PracticeTable.PracticeName AS [Practice Name], 'Primary Care | Pediatrics' AS [Practice Type], dbo.PracticeTable.PracticeAddressLine1 AS [Address 1], dbo.PracticeTable.PracticeAddressLine2 AS [Address 2], dbo.PracticeTable.PracticeCity AS Town, dbo.PracticeTable.PracticeZip AS [Zip Code], dbo.PracticeTable.PracticePhoneNumber AS Phone, dbo.PracticeTable.New_Pat_YN AS [New Pat YN], dbo.PracticeTable.Office_Hours AS [Office Hours], dbo.PracticeTable.PracticeWeSite AS Web, dbo.practicerecognition.PracRecMonth, dbo.practicerecognition.PracRecYear, dbo.practicerecognition.RecognitionArea, dbo.practicerecognition.RatingValue FROM dbo.PracticeTable RIGHT OUTER JOIN dbo.practicerecognition ON dbo.PracticeTable.OPNumber = dbo.practicerecognition.OPNumber WHERE (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.PracticeTable.PrimaryCare = 1) AND (dbo.PracticeTable.AgeCategory = N'Children Only') AND (dbo.practicerecognition.PracRecMonth = 12) OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP569') OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP143') OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP625') OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP795') OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP385') OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP570') OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP567') OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP567') OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP483') OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP260') AND (dbo.practicerecognition.PracRecYear = 2015) OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP0080') AND (dbo.practicerecognition.PracRecYear = 2015) OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP557') AND (dbo.practicerecognition.PracRecYear = 2015) OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP610') AND (dbo.practicerecognition.PracRecYear = 2015) OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP616') AND (dbo.practicerecognition.PracRecYear = 2015) OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP632') AND (dbo.practicerecognition.PracRecYear = 2015) OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP640') AND (dbo.practicerecognition.PracRecYear = 2015) OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP452') AND (dbo.practicerecognition.PracRecYear = 2015) OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP348') AND (dbo.practicerecognition.PracRecYear = 2015) OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP301') AND (dbo.practicerecognition.PracRecYear = 2015) OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP443') AND (dbo.practicerecognition.PracRecYear = 2015) OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP557') AND (dbo.practicerecognition.PracRecYear = 2015) OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP391') AND (dbo.practicerecognition.PracRecYear = 2015) OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'5651') AND (dbo.practicerecognition.PracRecYear = 2015) OR (dbo.PracticeTable.SiteStatus <> N'Closed') AND (dbo.practicerecognition.PracRecMonth = 12) AND (dbo.PracticeTable.OPNumber = N'OP0063') AND (dbo.practicerecognition.PracRecYear = 2015)
Comment