great job posting the DDL;
in this case, i think using ROW_NUMBER(), and a custom CASE expression to control the special order might work well:
SELECT * FROM
(
SELECT row_number() over(partition by cStudentID,School_Year,CourseID
ORDER BY CASE
WHEN TermCode='FG1'
THEN 1
WHEN TermCode='Q1'
THEN 2
ELSE 3
END) AS RW,*
FROM #TEMP
) MyAlias
WHERE
RW = 1
Lowell
--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!