 <p>Don't rely on order by when using mutlirows variable assignment.</p> <p>try this for instance:</p> <pre><code>DECLARE @c INT = 0 SELECT @c = @c + x FROM (VALUES(1),(2),(3)) AS src(x) WHERE x BETWEEN 1 AND 3 ORDER BY 1 - x DESC SELECT @c SET @c = 0 SELECT @c = @c + x FROM (VALUES(1),(2),(3)) AS src(x) WHERE x BETWEEN 1 AND 3 ORDER BY x DESC SELECT @c </code></pre> <p><a href="http://sqlmag.com/sql-server/multi-row-variable-assignment-and-order" rel="nofollow">http://sqlmag.com/sql-server/multi-row-variable-assignment-and-order</a></p>