How can I fix the divide by zero error when dividing by a case statement that many result in 0? This is happening because the query is grouped by hour, so if there are no abandons during one of the hours it is trying to divide the holding time by 0.
SELECT call_date as Date, DATEPART(hh, call_time) as Hour, COUNT(record_id) as Total_Calls,
SUM(case when time_connect = 0 then 1 else 0 end) as Abandons,
SUM(case when time_connect <> 0 then 1 else 0 end) as Calls_to_Agents,
sum(case when time_connect <> 0 then 0 else time_holding10 end)/SUM(case when time_connect = 0 then 1 else 0 end) as Hold_Abandon_Average
group by call_date, DATEPART(hh, call_time)