update 表A set ctime=left(ctime,6)+right('00'+convert(varchar,convert(int,rand()*60)),2)

解决方案 »

  1.   

    create table a (
    a int identity,
    b datetime
    )insert into a (b) values (getDate())select * from a 
    update a set b = '2005-01-01'
    declare @a int 
    declare  myCursor cursor  for select a from A
     
    open myCursor
     
    Fetch next From myCursor
    While @@FETCH_STATUS =0
    begin
       Fetch next From myCursor into @a 
    update a set b = dateadd(ss,round(rand()*60,0),b) where a = @a
    end
     
    Close myCursor
    Deallocate myCursordrop table a
      

  2.   

    用NEWID函数应该可以,写起来也麻烦。
      

  3.   

    --rand()*60   然后处理
      

  4.   

    agree to the '因为一次更新的话..只取一个随机数...用游标一条条更新才能真正的全部随机.
    '
      

  5.   

    update Test060107 set ctime=left(ctime,6)+right('00'+convert(varchar,convert(int,rand()*60)),2)select * from Test060107这样的语句不行的,一个随机数把所有行都更新了。
      

  6.   

    这样改一下,也能行啊楼主的编码最大ID应该为999吧,update 表A set ctime=left(ctime,6)+right('00'+cast(abs(cast(right('00'+cast(cast(rand()*(999/cast(cid as int))+10 as varchar) as varchar),2) as int)-40) as varchar),2)
      

  7.   

    update 表A set ctime=left(ctime,6)+right('00'+convert(varchar(2),convert(int,rand(checksum(newid()))*100) % 60),2)
      

  8.   

    我觉得fesxe(想飞的鸟)应该是对的,游标里面有点小错误
    open myCursor
    fetch next From myCursor into @a 
    while @@FETCH_STATUS =0
    begin
     update a set b = dateadd(ss,round(rand()*60,0),b) where a = @a
     fetch next From myCursor into @a 
    end
     
    Close myCursor
      

  9.   

    还是看看szztao(szztao)的方法吧。
      

  10.   

    update 表A 
    set ctime=left(ctime,6)+
        right('00'+convert(varchar(2),convert(int,rand()*60+convert(int,cid))%60),2)