我想查询日期从20070301至20080229之间,并且时间从中午1点至2点之间的记录,怎么完成,请指教

解决方案 »

  1.   

    --假设时间字段为dt
    select * from tb where (convert(varchar(10),dt,120) between '2007-03-01' and '2008-02-29') and (datepart(hour,dt) between 13 and 14)
      

  2.   

    select * from 表名 where datediff(dd,'2008-02-29',日期字段)>=0
    and datediff(dd,日期字段,'2008-03-01')>=0
    and datediff(hh,convert(varchar(10),日期字段,120)+' 13:00',日期字段)>=0
    and datediff(hh,日期字段,convert(varchar(10),日期字段,120)+' 14:00')>=0
      

  3.   


    --老乌龟的日期写反了。哈哈select * from 表名 where (convert(varchar(10),日期字段,120) between '2007-02-29' and '2008-03-01') and (datepart(hour,日期字段) between 13 and 14)
      

  4.   

     
    select * from tb where convert(char(10),tbdate,120) between '20070301'and'20080229'and convert(char(8),tbdate,108) between '13:00:00'and'14:00:00'