我的SQL Server 2000数据库中,有一个些日期型的数据需要更改,怎么才能把它们筛选出来,并且更改呢?
比如,某个字段值为“2006-07-26”,我要将这些字段的值全部改成“2006-07-28”。这个Update语句怎么写?
能不能不用DateAdd的方法做?

解决方案 »

  1.   

    --这样试一下
    Declare @t Table(Rq Datetime)
    Insert @t Select '2006-07-26'
    Union all Select '2006-07-26'
    Union all Select '2006-07-23'
    --Try
    Update @t
    Set Rq=DateAdd(day,2,Rq)
    Where DateDiff(day,Rq,'2006-7-26')=0
    --
    Select * From @t
      

  2.   

    Declare @t Table(Rq Datetime)
    Insert @t Select '2006-07-26'
    Union all Select '2006-07-26'
    Union all Select '2006-07-23'
    --Try
    Update @t
    Set Rq='2006-7-28 'Where rq='2006-7-26'
    --
    Select * From @t
      

  3.   

    Declare @t Table(Rq Datetime)
    Insert @t Select '2006-07-26'
    Union all Select '2006-07-26'
    Union all Select '2006-07-23'
    --Try
    Update @t
    Set Rq=DateAdd(day,2,Rq)
    --Where DateDiff(day,Rq,'2006-7-26')=0
    --改为
    where rq='2006-7-26'  --这样可以用上索引
      

  4.   

    看来答案都是一样的呢!
    我还以为可以直接用Update进行修改就行了呢!
    原来还得这么复杂。
    谢谢各位大虾了!
      

  5.   

    update a
    set rq='20060728' where rq='20060726'这样写有问题吗?
      

  6.   

    看你要怎么做了,你也可以
    update TA
    set rq = replace('2006-07-26','26','28')