Try this:
select @NewCourse =
(select min(Courses.CourseID)
from @Courses Courses
left outer join @Enrollment Enrollment
on Courses.CourseID = Enrollment.CourseID
and Student = @Student
where Enrollment.CourseID is null);
See if that'll do what you need.
- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread
"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon