已有记录表添加特定排序主键ID

  1. DECLARE Employee_Cursor CURSOR FOR
  2. SELECT Updatetime,id
  3. FROM tblSimAccountHistory
  4. Order by Updatetime,id
  5. OPEN Employee_Cursor
  6. DECLARE @Updatetime datetime
  7. DECLARE @id decimal
  8. DECLARE @HID decimal
  9. select @HID=1
  10. FETCH NEXT FROM Employee_Cursor 
  11. INTO @Updatetime, @id
  12. WHILE @@FETCH_STATUS = 0
  13. BEGIN
  14.     
  15.     update tblSimAccountHistory set HID=@HID where ID=@id and updatetime=@Updatetime
  16.     select @HID= @HID + 1
  17.     FETCH NEXT FROM Employee_Cursor
  18.   INTO @Updatetime, @id
  19. END
  20. CLOSE Employee_Cursor
  21. DEALLOCATE Employee_Cursor
原文地址:https://www.cnblogs.com/gpwzw/p/12147488.html