title: SQL Server Incrementing a counter in Update
body: <p>I'm updating some columns and incrementing a counter whenever I change a row.</p>
  
  <p>The update statement is the result of a join (simplified code below):</p>
  
  <pre><code>update @to
      set
          t.num += 1
      from @to t
      join @source s
          on t.id = s.id
  </code></pre>
  
  <p>When I update one row more than once, the columns hold the last value (as they should), but the counter is only incremented once.  So if the join returns (id = 1, id = 1), my table holds (id = 1, num = 1) rather than (id = 1, num = 2).</p>
  
  <p>There are ways to get around this (another join on a select count, for example), but I wonder if there's a way to keep it simple.</p>