title: Get AVG ignoring Null or Zero values
body: <p>How can I get the <code>AVG</code> of a column ignoring <code>NULL</code> and zero values?</p>
  
  <p>I have three columns to get their average, I try to use the following script:</p>
  
  <pre><code>SELECT distinct
       AVG(cast(ISNULL(a.SecurityW,0) as bigint)) as Average1
       ,AVG(cast(ISNULL(a.TransferW,0) as bigint)) as Average2
       ,AVG(cast(ISNULL(a.StaffW,0) as bigint)) as Average3
  FROM Table1 a,  Table2 b
  WHERE a.SecurityW &lt;&gt; 0 AND a.SecurityW IS NOT NULL
  AND a.TransferW&lt;&gt; 0 AND a.TransferWIS NOT NULL
  AND a.StaffW&lt;&gt; 0 AND a.StaffWIS NOT NULL
  AND MONTH(a.ActualTime) = 4
  AND YEAR(a.ActualTime) = 2013
  </code></pre>
  
  <p>I don't get any results, however the three columns have values including NULL and zeros!</p>
  
  <p>Is there anyway to exclude null values before getting the average?</p>
  
  <p>example: <code>AVERAGE(NOTNULL(SecurityW))</code></p>