In t-sql 2012, I have the following sql:
declare @gradYear int = 2017
SELECT distinct graduation.personID
FROM [TEST].[dbo].[Graduation] graduation
where graduation.gradyear = @gradYear
SELECT distinct personID
FROM #gradPersonID graduation
where personID NOT in
(select distinct TranscriptCourse.personID from #gradPersonID graduation
join [TEST].[dbo].[TranscriptCourse] TranscriptCourse
on TranscriptCourse.personID = graduation.personID
where TranscriptCourse.grade between '09' and '12'
and @gradYear - 4 = TranscriptCourse.endYear)
DROP table #gradPersonID
I am joining to the graduation table so I can find students that are scheduled to graduate in a certain year. In this case the year is 2017.
What I am looking for is from the TranscriptCourse table by personID if there are no records where the endYear = 2014. Somehow I canot
seem to get the 'NOT IN' or 'NOT EXISTS' to work.
Thus would you show me how to change this sql so I canaccomplish my goal?