请问一下,我的表中的字段的时间为日期时间型的,我想通过查询返回这样的结果
如字段的值为:
2010-03-31 02:00:00.000
2010-03-31 09:00:00.000
我想获得当该时间小于8点时返回当前日期+1 即2010-04-01
                       否则返回当前日期 即2010-03-31

解决方案 »

  1.   

    case when hour(col)<8 then dateadd(day,1,col) else col end
      

  2.   

    select 
    case when convert(varchar(8),fdate,108) < '08:00:00' then fdate + 1 else fdate end from tb
      

  3.   

    select convert(varchar(10),dateadd(dd,1,col) ,120) from tb where datepart(hh,col) < 8
      

  4.   

    create table tb(col datetime)
    insert into tb values('2010-03-31 02:00:00.000')
    insert into tb values('2010-03-31 09:00:00.000')
    goselect case when datepart(hh,col) < 8 then convert(varchar(10),dateadd(dd,1,col) ,120) else convert(varchar(10),col ,120) end from tbdrop table tb
    /*
               
    ---------- 
    2010-04-01
    2010-03-31(所影响的行数为 2 行)*/
      

  5.   


    将大乌龟的语句改一下就可以了啊,dataadd(-1