You already attempt to filter out NULL
values with NOT NULL
. I have changed this to IS NOT NULL
in the WHERE
clause so it will execute. We can refactor this by removing the ISNULL
function in the AVG
method. Also, I doubt you'll actually need bigint
so we can remove the cast.
SELECT distinct
AVG(a.SecurityW) as Average1
,AVG(a.TransferW) as Average2
,AVG(a.StaffW) as Average3
FROM Table1 a, Table2 b
WHERE a.SecurityW <> 0 AND a.SecurityW IS NOT NULL
AND a.TransferW<> 0 AND a.TransferWIS IS NOT NULL
AND a.StaffW<> 0 AND a.StaffWIS IS NOT NULL
AND MONTH(a.ActualTime) = 4
AND YEAR(a.ActualTime) = 2013