id  timestamp
1   2012-5-4 17:07:35
2   2012-5-4 17:07:35
3   2012-5-4 17:07:35
如何更新使得下一条记录中timestamp的值是上一条中时间+1  第一条的时间不变。坐等大侠

解决方案 »

  1.   

    DECLARE @timestamp DATETIME 
    UPDATE TAB SET 
      @timestamp = CASE WHEN @timestamp IS NULL THEN timestamp ELSE DATEADD(SECOND,1,@timestamp) END
      ,timestamp = @timestamp
      

  2.   


    --> 测试数据:[test]
    if object_id('[test]') is not null drop table [test]
    create table [test]([id] int,[timestamp] datetime)
    insert [test]
    select 1,'2012-5-4 17:07:35' union all
    select 2,'2012-5-4 17:07:35' union all
    select 3,'2012-5-4 17:07:35'update test
    set [timestamp]=DATEADD(DD,id-1,(select [timestamp] from test where id=1))select * from test/*id timestamp
    1 2012-05-04 17:07:35.000
    2 2012-05-05 17:07:35.000
    3 2012-05-06 17:07:35.000*/