title: SQL divide by zero with a sum function
body: <p>I am having problems with dividing by zero.  If the denominator is zero I would like the value to be zero.  When I try using <code>nullif</code>, I end up with a zero or one for the calculated value.</p>
  
  <p>Here is the SQL:</p>
  
  <pre><code>Select 
      StateCode, Month1Date,(Sum(Order)/Sum(Value)) as myValue    
  from tblOrders    
       inner join tblStates on OrderStateCode = StateCode    
  group by StateCode, Month1Date
  </code></pre>