title: T-SQL variable counter not incrementing
body: <p>I need to increment counter and update rows in my db table, but some reason it is not incrementing.
  Can anyone see what's wrong with this T-SQL?</p>
  
  <pre><code>DECLARE @id INT
  DECLARE @name NVARCHAR(100)
  DECLARE @getid CURSOR
  declare @counter int
      set @counter = 0
  SET @getid = CURSOR FOR
  SELECT ShipmentTrackingNumber,
         Courier
  FROM   Shipping WHERE (ShipmentTrackingNumber = '')
  OPEN @getid
  FETCH NEXT
  FROM @getid INTO @id, @name
  WHILE @@FETCH_STATUS = 0
  BEGIN
      UPDATE SHipping SET ShipmentTrackingNumber = 'STN00000' + cast(@counter as VARCHAR(16))
      set @counter = @counter + 1
      FETCH NEXT
      FROM @getid INTO @id, @name
  END
  CLOSE @getid
  DEALLOCATE @getid
  </code></pre>