title: SQL Server: UPDATE a table by using ORDER BY
body: <p>I would like to know if there is a way to use an order by clause when updating a table. I am updating a table and setting a consecutive number, that's why the order of the update is important. Using the following sql statement, I was able to solve it without using a cursor:</p>
  
  <pre><code>DECLARE @Number INT = 0
  
  UPDATE Test
  SET @Number = Number = @Number +1
  </code></pre>
  
  <p>now what I'd like to to do is an order by clause like so:</p>
  
  <pre><code> DECLARE @Number INT = 0
  
   UPDATE Test
   SET @Number = Number = @Number +1
   ORDER BY Test.Id DESC
  </code></pre>
  
  <p>I've read: <a href="https://stackoverflow.com/questions/655010/how-to-update-and-order-by-using-ms-sql">How to update and order by using ms sql</a> The solutions to this question do not solve the ordering problem - they just filter the items on which the update is applied.</p>
  
  <p>Take care,
  Martin</p>