I have a simple general weighed average computation in my SELECT:
SELECT ROUND(SUM((G.UnitsAcademic*GD.Grade))/SUM(G.UnitsAcademic),3) AS 'GWA'
FROM Gradesheet G
INNER JOIN GradeSheetDetail AS GD
ON GD.GradesheetId=G.GradesheetId
However, some students have non-numeric grades (such as “No Exam”) or blank grades. The code above still computes and returns a value.
I would like it to return a blank (” “) when a non-numeric value gets involved in the computation. Is there a way for SQL to do this?
Try this:
First, you need to check if there is at least one non-numeric field, if ‘yes’ then return blank, else calculate aggregate.