title: How to add row number column in SQL Server 2012
body: <p>I'm trying to add a new column to an existing table, where the value is the row number/rank. I need a way to generate the row number/rank value, and I also need to limit the rows affected--in this case, the presence of a substring within a string.</p>
  
  <p>Right now I have:</p>
  
  <pre><code>UPDATE table
  SET row_id=ROW_NUMBER() OVER (ORDER BY col1 desc) FROM table
  WHERE CHARINDEX('2009',col2) &gt; 0
  </code></pre>
  
  <p>And I get this error:</p>
  
  <pre><code>Windowed functions can only appear in the SELECT or ORDER BY clauses.
  </code></pre>
  
  <p>(Same error for <code>RANK()</code>)</p>
  
  <p>Is there any way to create/update a column with the ROW_NUMBER() function? FYI, this is meant to replace an incorrect, already-existing "rank" column.</p>