有table A ,有字段ID,InputDate.
现在想更新id,不过需要根据inputdate递增顺序更新
declare @i int set @i=1 
update A set @i=@i+1,id=100000000+@i 
不知道递增顺序怎么写,求教!

解决方案 »

  1.   

    create table table2(id int,inputdate datetime)
    insert table2
    select null,'2005-5-1'
    union all select null,'2005-5-7'
    union all select null,'2005-5-4'update a set id=(select count(1) from table2 b where b.inputdate<=a.inputdate) from table2 a
    select * from table2
    drop table table2??
      

  2.   

    select [id]=identity(int,1,1) ,InputDate into #t from A order by InputDate
    update A set [id]=100000000+T.[id] from #t T where A.InputDate=T.InputDate
      

  3.   

    select  identity(int,100000001,1)  as  new,*  into  #temp  from  table  order by InputDateupdate table set table.id=#temp.new from table a,#temp.b where a.id=b.id
      

  4.   

    日期相同的多了,怎么单独作为条件
    你创建临时表的id怎么和现在表的id相同呢