create table #temp(cStudentID VARCHAR(12),cCurrentGradeCode VARCHAR(12),cAnticipatedGradeCode VARCHAR(12),)insert into #temp values ('002121506','99','99')insert into #temp values ('002124963','99','01')insert into #temp values ('002141019','99','99')insert into #temp values ('002147726','01','99')insert into #temp values ('002203944','02','03')insert into #temp values ('002206137','99','04')insert into #temp values ('002220423','03','99')
cStudentID cCurrentGradeCode cAnticipatedGradeCode002124963 99 01002147726 01 99002203944 02 03002206137 99 04002220423 03 99
select * from #tempwhere cCurrentGradeCode + cAnticipatedGradeCode <> '9999' order by cStudentID
select t.* from #temp tjoin #temp t2 on t.cStudentID = t2.cStudentID where t2.cCurrentGradeCode <> '99' or t2.cAnticipatedGradeCode <> '99'order by t2.cStudentID
select cStudentID, cCurrentGradeCode, cAnticipatedGradeCodefrom #tempwhere cCurrentGradeCode <> '99' or cAnticipatedGradeCode <> '99'