我想写一个句子,用来查询在某一天的数据。 我用数据库记录的时间都是  datetime数据类型。
而数据值是形如  2007-08-07 20:04:02而我现在想查询  2007-08-07  即8月7日的数据。
我在页面里得到的日期返回值是  年月日,即 2007-08-07 。那么我的sql句子应该怎么写呢? 

解决方案 »

  1.   

    select * from 表 where datediff(dd,'2007-08-07',date)=0  --  date为你的字段
      

  2.   

    将数据库中的datetime型加工一下:
    select convert(varchar(10),'2007-08-07 20:04:02',121)
      

  3.   


    select * 
    from 表 
    where DATEPART(m,日期字段)=8 
        AND DATEPART(d,日期字段)=7
      

  4.   

    select * from 表 where convert(varchar(10),日期字段,121)='2007-08-07'
      

  5.   

    ljsql(第 1 行: '脑子' 附近有语法错误。) 
    这家伙回答的真牛,真是好方法.select * from 表 where year(日期)=2007 and month(日期)=8 and day(日期)=7select * from 表 where substring(cast(日期 as varchar(30),1,10)='2007-08-07';