title: Oracle Divisor is equal to zero
body: <p>How do I wrap a DECODE around this query to handle a zero divisor without computing the denominator summation twice? I don't want to return anything other than <code>thedate</code> and the rounded percentage.</p>
  
  <pre><code>SELECT thedate, ROUND (100*
    SUM( case when TRUNC(ACTIVITY_END_DATE) &lt;= thedate
       AND TRUNC(ACTIVITY_END_DATE) &gt;= add_months( trunc(thedate,'mm'), -12) 
       AND trunc(ACTIVITY_END_DATE) &lt;= trunc(ACTIVITY_NEED_DATE) 
       AND SYSDATE  &gt;=  trunc(thedate,'mm') then 1 else 0 end )  
    /
    SUM( case when TRUNC(ACTIVITY_END_DATE) &lt;= thedate 
       AND TRUNC(ACTIVITY_END_DATE) &gt;= add_months( trunc(thedate,'mm'), -12) 
       AND SYSDATE  &gt;=  trunc(thedate,'mm') then 1 else 0 end ) ) as OTR12 
         FROM TEST
         cross join (  select add_months(last_day(SYSDATE), level-7) as thedate 
         from dual connect by level &lt;= 12  )  
         GROUP BY thedate 
         ORDER BY thedate 
  </code></pre>
  
  <p>It seems with the DECODE, I'd have to do the denominator summation twice<br>
  <code>DECODE(denominator_summation,0,NULL, numerator_summation / denominator_summation)</code></p>