Quicker with SQL to SUM 0 values or exclude them?
<p>I want to SUM a lot of rows.</p>

<p>Is it quicker (or better practice, etc) to do Option A or Option B?</p>

<p><strong>Option A</strong></p>

<pre><code>SELECT
    [Person]
    SUM([Value]) AS Total
FROM
    Database
WHERE
    [Value] &gt; 0
GROUP BY
    [Person]
</code></pre>

<p><strong>Option B</strong></p>

<pre><code>SELECT
    [Person]
    SUM([Value]) AS Total
FROM
    Database
GROUP BY
    [Person]
</code></pre>

<p>So if I have, for Person X:</p>

<pre><code>0, 7, 0, 6, 0, 5, 0, 0, 0, 4, 0, 9, 0, 0
</code></pre>

<p>Option A does:</p>

<pre><code>a) Remove zeros
b) 7 + 6 + 5 + 4 + 9
</code></pre>

<p>Option B does:</p>

<pre><code>a) 0 + 7 + 0 + 6 + 0 + 5 + 0 + 0 + 0 + 4 + 0 + 9 + 0 + 0
</code></pre>

<p>Option A has less summing, because it has fewer records to sum, because I've excluded the load that have a zero value.  But Option B doesn't need a WHERE clause.</p>

<p>Anyone got an idea as to whether either of these are significantly quicker/better than the other?  Or is it just something that doesn't matter either way?</p>

<p>Thanks :-)</p>