我有一张表,字段ID的内容是从别的表中提过来的,所以ID号是乱的。我想把ID按照它在该表的摆放顺序对ID的值用顺序号进行填充,如该记录在表中的顺序号是1则ID编号就填1,以此类推。但不能循环一条一条的对ID编号进行填充,那样循环一遍很费时间。不知道有没有该SQL语句?

解决方案 »

  1.   

    --try
    declare @i intset @i=0update 表名 set 序号=@i,@i=@i+1
      

  2.   

    update a set id=(select count(1) from [table] where id<=a.id) from [Table] a
      

  3.   

    ID不重复吧?select id1=identity(int 1,1) , id into temp from tbupdate tb
    set id = id1
    from tb,temp 
    where tb.id = temp.iddrop table temp
      

  4.   

    各位老大的方法都不错!多谢指教!采用wangtiecheng的。结贴。