请问一下,我的表中的字段的时间为日期时间型的,我想通过查询返回这样的结果
如字段的值为:
2010-03-31 02:00:00.000
2010-03-31 09:00:00.000
我想获得当该时间小于8点时返回当前日期+1 即2010-04-01
否则返回当前日期 即2010-03-31
如字段的值为:
2010-03-31 02:00:00.000
2010-03-31 09:00:00.000
我想获得当该时间小于8点时返回当前日期+1 即2010-04-01
否则返回当前日期 即2010-03-31
case when convert(varchar(8),fdate,108) < '08:00:00' then fdate + 1 else fdate end from tb
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 行)*/
将大乌龟的语句改一下就可以了啊,dataadd(-1