select A.grading, CASE WHEN count(B.IDno) = 0 THEN count(C.IDno) ELSE COUNT(B.IDno) end as myCountFrom Aleft join B on A.fkIDno = B.IDno and A.grading = 1left join C on A.fkIDno = C.IDno and A.grading = 2Where A.grading > 3
select A.grading, ISNULL(NULLIF(count(B.IDno),0),COUNT(B.IDno)) as myCountFrom Aleft join B on A.fkIDno = B.IDno and A.grading = 1left join C on A.fkIDno = C.IDno and A.grading = 2Where A.grading > 3
select A.grading, (1-SIGN(COUNT(B.IDno)))*COUNT(C.IDno) + COUNT(B.IDno) as myCountFrom Aleft join B on A.fkIDno = B.IDno and A.grading = 1left join C on A.fkIDno = C.IDno and A.grading = 2Where A.grading > 3