一个表中 有 个时间 字段给这个时间字段增加天数 并根据 时间字段内的时间 如果比现在大则加上天数 
如果比现在的时间小则更新为当前时间+天数

解决方案 »

  1.   


    create table #tb(
    i int identity(1,1),
    dtime datetime
    )
    insert into #tb
    select '2007-01-01' union all
    select '2009-01-01' 
    -- 加3天
    update #tb
    set dtime = case when dtime > getdate() then dateadd(day,3,dtime)
    when dtime < getdate() then dateadd(day,3,getdate())
    else dtime 
       end
    where <条件>select * from #tbdrop table  #tb
      

  2.   

    use tempdb
    if object_id('dbo.#t') is not null
       drop table dbo.#t
    go
    create table #t(id int identity,date_dt datetime)
    insert into #t 
    select '2007-1-1' union all
    select '2009-1-1'
    select * from #tupdate #t
    set date_dt=case when date_dt>getdate() then dateadd(dd,abs(datediff(dd,getdate(),date_dt)),date_dt)
                     when date_dt<getdate() then dateadd(dd,3,getdate())
                     else date_dt
                     end
    where date_dt='2007-1-1'select * from #t
      

  3.   

    非常感谢 原来还有 case  明天加分