现有字段visittime,类型为datetime,我想把a和输入的日期进行比较(大于小于或等于)这个好象可以解决,我用的SQL语句是:
"select * from visit where name='周小红' and convert(varchar(10),visittime,121)<'2006-01-07'"  表示访问时间在2006-01-07之前的。我想问一下,后面的具体时间如何提取出来进行比较呢?
比如我想查询时间大于08:00:00的,该怎么写SQL语句呢?
请高手指点。

解决方案 »

  1.   

    select convert(char(10),getdate(),120)
    select convert(char(8),getdate(),108)
      

  2.   

    比如我想查询时间大于08:00:00的,该怎么写SQL语句呢?
    ------------------------------
    select * from visit where convert(char(8),visittime,108)>'08:00:00'
      

  3.   

    select *
    fromt visit 
    where DATEPART ( hh, visittime)< 8
      

  4.   

    "select * from visit where name='周小红' and convert(varchar(10),visittime,121)<'2006-01-07' and DATEPART (hh,visittime)>='14'and DATEPART (mm,visittime)>'0'and DATEPART (hh,visittime)>'0'"  返回结果:
    周小红  2005-11-3 18:41:17  
    周小红  2005-11-15 16:24:30  
    周小红  2005-11-20 14:02:46  
    周小红  2005-11-20 14:03:16  
    周小红  2005-12-1 18:30:43  
    周小红  2005-12-23 14:28:03  
    周小红  2005-12-26 18:04:53  
    周小红  2005-12-29 17:52:09  根据四楼的启发,得出了想要的结果,可是我想问一下,一定要写这么长吗?呵呵.
      

  5.   


    select * from visit where name='周小红' and convert(varchar(10),visittime,121)<'2006-01-07' and convert(char(8),visittime,108)>'14:00:00'这样没结果返回???
      

  6.   

    ---try
    select * 
    from visit
     where name='周小红' and convert(varchar(10),visittime,121)<'2006-01-07' and right(convert(varchar(19),visittime,120),8)>'14:00:00'
      

  7.   

    DATEPART (hh,visittime)>='14'and DATEPART (mm,visittime)>'0'and DATEPART (hh,visittime)>'0'----datepart 返回的是int ,楼主比较有问题,
    根据你的意思是大于14点的,  对datepart 来mm 是月份,mi 是分,ss  是秒
      

  8.   

    select * from visit where name='周小红' and convert(varchar(10),visittime,121)<'2006-01-07' and convert(char(8),visittime,108)>'14:00:00'这样没结果返回???0-----我估计楼主连接数据库引擎不同造成的,用ODBC的标准肯定不会错