我有一个表A我现在想要批量更新表A里的时间.如:
Update A Set a_time=gedate() where a_userid='aaa'
虽然这样可以批量更新时间.但更新后的时间都是一样的有没有办法使更新后的时间,每条数据更新的时间都增加1秒,如:ID    a_time
1     2010-07-27 17:13:042     2010-07-27 17:13:053     2010-07-27 17:13:06..................

解决方案 »

  1.   

    declare @t datetime
    select @t = getdate()
    Update A 
    Set a_time=@t,@t=dateadd(ss,1,@t)
    where a_userid='aaa'
      

  2.   

    if object_id('[TB]') is not null drop table [TB]
    go
    create table [TB]([ID] int,[a_time] datetime)
    insert [TB]
    select 1,'2010-07-27 17:13:04' union all
    select 2,'2010-07-27 17:13:05' union all
    select 3,'2010-07-27 17:13:06'
    GOdeclare @n int
    set @n=0
    update tb 
      set a_time=dateadd(ss,@n,getdate()),@n=@n+1select * from tb
    /**
    ID          a_time
    ----------- -----------------------
    1           2010-07-27 17:58:33.840
    2           2010-07-27 17:58:34.840
    3           2010-07-27 17:58:35.840(3 行受影响)
    **/
      

  3.   


    Set a_time=@t,@t=dateadd(ss,1,@t)
    请问下中间的@t,@t是代表什么意思..谢谢了.
      

  4.   

    @t是声明的临时变量, declare @t datetime
      

  5.   


    @t,@t=dateadd(ss,1,@t)我想问的是这段是什么意思
      

  6.   

    Update A Set a_time=DATEADD(SS,ID,gedate()) where a_userid='aaa'
      

  7.   

    变量
    declare @t
    在存储过程或自定义函数中就这样定义