title: How to update a column with sequential numbers using cursor in SQL Server?
body: <p>Expected result is </p>
  
  <pre><code>code    descd   slnum
  ======================
  10       a       1
  11       b       2
  12       c       3
  </code></pre>
  
  <p>I have tried like this but I'm missing somewhere</p>
  
  <pre><code>DECLARE @DF TABLE(code int, descd varchar(7), slnum int)
  
  INSERT INTO @DF VALUES(10, 'a', 0), (11, 'b', 0), (12, 'c', 0)
  
  DECLARE @s as INT = 0
  DECLARE @code as INT = 0
  
  DECLARE scursor CURSOR FOR
      SELECT code, slnum 
      FROM @DF 
      FOR UPDATE of slnum
  
  OPEN scursor
  
  FETCH NEXT FROM scursor INTO @code, @s
  
  WHILE(@@FETCH_STATUS = 0)
  BEGIN
      UPDATE @DF
      SET @s = slnum = @s + 1 
      WHERE current of scursor
  
      FETCH NEXT FROM scursor INTO @code, @s
  END
  
  CLOSE scursor
  DEALLOCATE scursor
  </code></pre>