No need of IF you can just write this asSELECT t.StudentDimKey,COALESCE((t.TESTA +t.TESTB)/2,t.TESTA,t.TESTB) AS [Value]FROM(Select S.StudentDimKey, (select ISNULL(R.Score, NULL) from CLT_StudentAssessmentRawFact R, CLT_LessonPlanDim L where L.LessonPlanKey = 1 and L.LessonPlanDimKey = R.LessonPlanDimKey and StudentDimKey = S.StudentDimKey) as TESTA,(select ISNULL(R.Score, NULL) from CLT_StudentAssessmentRawFact R, CLT_LessonPlanDim L where L.LessonPlanKey = 2 and L.LessonPlanDimKey = R.LessonPlanDimKey and StudentDimKey = S.StudentDimKey) as TESTBfrom CLT_StudentPlacementFact P, CLT_StudentDim S, CLT_ClassHierarchyDim H, CLT_StudentClassFact Cwhere P.StudentDimKey = S.StudentDimKeyand H.ClassHierarchyDimKey = C.ClassHierarchyDimKeyand S.StudentDimKey = C.StudentDimKeyand S.StatusCode = 'A'and S.CurrentRecord = 1and S.SchoolID = 87577)t