title: Divide by zero error returns for queries with no data
body: <p>I'm in the process of trying to figure out a way to solve this divide by zero error.  The current challenge I'm facing comes from <a href="https://stackoverflow.com/questions/21145232/how-to-accurately-figure-percentage-of-a-finite-total">this question I asked not too long ago.</a>  </p>
  
  <p>Here's the Code I'm using that I'm plugging into reports stretching out into the end of the year:</p>
  
  <pre><code>SELECT CAST(ROUND((.01 * 2541) / Count(date_record_entered), 1) AS decimal(5,1)) 
  FROM dbo.tablename
  WHERE date_record_entered IS NOT NULL 
  and date_record_entered &gt;= 20131201 
  AND date_record_entered &lt;= 20131231
  </code></pre>
  
  <p>When it comes to current or previous months reports, there aren't any issues with the data populating.  However, when the reports past the current month are accessed, I get the following error in SQL (and a similar error in C#/ASP.NET):</p>
  
  <pre><code>Msg 8134, Level 16, State 1, Line 1
  Divide by zero error encountered
  </code></pre>
  
  <p>Here's what I've tried with no success.</p>
  
  <p>Sample #1</p>
  
  <pre><code>SELECT CASE WHEN date_record_entered = 0 then null
  ELSE CAST(ROUND(.01 * 2541 / COUNT(date_record_entered), 
  AS deciamal (5,1)
  FROM dbo.tablename 
  WHERE date_record_entered IS NOT NULL 
  AND date_record_entered &gt;= 20140201 
  and date_record_entered &lt;= 20140228
  </code></pre>
  
  <p>Sample #2</p>
  
  <pre><code>SELECT CAST(ROUND((.01 * 2541) / NULLIF(Count(date_record_entered), 1) 
  AS decimal(5,1))) 
  FROM dbo.tablename 
  WHERE date_record_entered IS NOT NULL 
  and date_record_entered &gt;= 20140201 
  AND date_record_entered &lt;= 20140228
  </code></pre>
  
  <p>Sample #3 </p>
  
  <pre><code>SET ARITHABORT OFF
  SET ANSI_WARNINGS OFF
  
  SELECT CAST(ROUND(.01 * 2541 / COUNT(date_record_entered ), 1) AS decimal(5,1)) 
  FROM dbo.tablename  
  WHERE date_record_entered IS NOT NULL 
  AND date_record_entered &gt;= 20140201 
  and date_record_entered  &lt;= 20140228
  </code></pre>
  
  <p>Now this third one works in SQL but I haven't found a way to do this with a gridview/c#.</p>
  
  <p>I know this may be something really simple but I'm just spinning my wheels at this point.  </p>