I'm running a query to tally up some numbers and it seems to be running super slow. This is on an MSSQL server. It takes about 22 seconds to run the query with only 34 records returned. The problem is that I'm running multiple SUM's at the same time and the execute time adds up. I've simplified the sql statement here to the barebones of what i need. How do i run this faster?
SELECT
SUM(case when (claims.dateon >= '20161110' AND claims.dateon < '20161117') AND entries.errorCode NOT IN('DP','RB','WP','PE','OV') then entries.refundDue else 0.0 end) as rate1
FROM auditors
INNER JOIN claims
ON claims.auditorID = auditors.auditorID
AND claims.status='closed'
--AND (claims.dateon >= '20161020' AND claims.dateon < '20161117')
INNER JOIN entries
ON claims.rID = entries.rid
WHERE claims.status = 'closed'
AND (claims.dateon >= '20161020' AND claims.dateon < '20161117')
GROUP BY auditors.auditorID