Hello,
I have a view that returns records based on whether an Instructor has not taught a class within a 22, 24 or 25 month period and what classes an Instructor has taught are outside the date range specified in the WHERE clause.
My problem is there might be Instructors who have never taught a class. I tried NOT EXISTS and NOT IN with no luck. Here's my latest attempt....
SELECT MAX(IC.certificationDate) AS MaxCertDate, I.instLName + ', ' + ISNULL(I.instSuffix, '') + ' ' + I.instFName + ' ' + ISNULL(I.instMName, '')
AS instFullName, I.instAddress, I.instCity + ', ' + I.instState + '. ' + I.instZip AS instFullCSZ, I.instSSN, IC.certificationID, MAX(C.classDate)
AS MaxClassDate, I.instID, TCC.CNTY_NAME AS workCounty, TCC.CNTY_REGION AS workRegion, IC.certificationType, IC.certificationStatus,
C.classType, DATEDIFF(m, IC.certificationDate, GETDATE()) AS monthFlag
FROM dbo.Instructors I INNER JOIN
dbo.Instructor_Certifications IC ON I.instID = IC.instID INNER JOIN
dbo.Classes C ON I.instID = C.instID INNER JOIN
dbo.Tn_Counties_Cat TCC ON I.instWorkCounty = TCC.CNTY_ID
WHERE (DATEDIFF(m, IC.certificationDate, GETDATE()) = 22 OR DATEDIFF(m, IC.certificationDate, GETDATE()) = 24 OR DATEDIFF(m, IC.certificationDate, GETDATE()) = 25) AND (C.classDate NOT BETWEEN IC.certificationDate AND GETDATE()) OR (C.classID NOT IN(SELECT classID
FROM Classes
WHERE I.instID = C.instID))
What would be the best way to detect the absence of a record in the child table?
Thanks
I have a view that returns records based on whether an Instructor has not taught a class within a 22, 24 or 25 month period and what classes an Instructor has taught are outside the date range specified in the WHERE clause.
My problem is there might be Instructors who have never taught a class. I tried NOT EXISTS and NOT IN with no luck. Here's my latest attempt....
SELECT MAX(IC.certificationDate) AS MaxCertDate, I.instLName + ', ' + ISNULL(I.instSuffix, '') + ' ' + I.instFName + ' ' + ISNULL(I.instMName, '')
AS instFullName, I.instAddress, I.instCity + ', ' + I.instState + '. ' + I.instZip AS instFullCSZ, I.instSSN, IC.certificationID, MAX(C.classDate)
AS MaxClassDate, I.instID, TCC.CNTY_NAME AS workCounty, TCC.CNTY_REGION AS workRegion, IC.certificationType, IC.certificationStatus,
C.classType, DATEDIFF(m, IC.certificationDate, GETDATE()) AS monthFlag
FROM dbo.Instructors I INNER JOIN
dbo.Instructor_Certifications IC ON I.instID = IC.instID INNER JOIN
dbo.Classes C ON I.instID = C.instID INNER JOIN
dbo.Tn_Counties_Cat TCC ON I.instWorkCounty = TCC.CNTY_ID
WHERE (DATEDIFF(m, IC.certificationDate, GETDATE()) = 22 OR DATEDIFF(m, IC.certificationDate, GETDATE()) = 24 OR DATEDIFF(m, IC.certificationDate, GETDATE()) = 25) AND (C.classDate NOT BETWEEN IC.certificationDate AND GETDATE()) OR (C.classID NOT IN(SELECT classID
FROM Classes
WHERE I.instID = C.instID))
What would be the best way to detect the absence of a record in the child table?
Thanks