title: SQL Server : increment INT column using variable
body: <p>Trying to insert an order column into some records, based on another field. Normally not a problem in MySQL, but in SQL Server I can't quite understand the syntax here. </p>
  
  <p>This is what I have:</p>
  
  <pre><code>DECLARE @a int
  SET @a = 1
  
  UPDATE tablename 
  SET order_position = @a:=@a+1  
  WHERE table_id = xxx
  </code></pre>
  
  <p>But part of me thinks this is going down the route of a function/procedure as opposed to a one hit <code>UPDATE</code> query.</p>
  
  <p>Sorry, but I wrote this as a MySQL database person, not familiar with variables with SQL Server so could be a little wrong.</p>
  
  <p>I need to run this on a load of records one by one, and I want the order_position column to be 1-7 (where there are 7 records), etc..</p>
  
  <p>Thanks, Chris</p>