现有一数据表"glcity_pl"中定义一字段"pl_dt"成datetime类型,
该数据表中有一条记录存在,其中字段"pl_dt"的值为“2008-4-10 9:54:30”,
但做如下的查询,怎么会查不出这条记录呢?select * from glcity_pl where (pl_dt - 2008-04-08) >= 0 and (pl_dt - 2008-04-16) <= 0如果“select * from glcity_pl where (pl_dt - 2008-04-08) >= 0”这样查就可把这条记录查出来!
请问我的错误在哪呀?先谢谢了!或者要怎么才能查出来?

解决方案 »

  1.   

    加'2008-04-08'或者用datediff
    或者用between
      

  2.   


    select * from glcity_pl where (pl_dt - '2008-04-08') >= 0 and (pl_dt - '2008-04-16')  <= 0 
      

  3.   

    改为select * from glcity_pl where (pl_dt - 2008-04-08) >= 0 and (pl_dt - 2008-04-16)  >= 0 
    或者select * from b where datediff(dd,convert(char(10),pl_dt,120) , '2008-04-08') <= 0 
       and datediff(dd,convert(char(10),pl_dt,120), '2008-04-16') >= 0
      

  4.   

    我这样做
    select * from glcity_pl where DATEDIFF(day,pl_dt,2008-04-08) <= 0 and DATEDIFF(day,2008-04-16,pl_dt) >= 0已解决了!
    多谢zanyzyg及wgzaaa朋友的帮忙!
      

  5.   

    我这句语句还是有问题的,
    select * from glcity_pl where DATEDIFF(day,pl_dt,2008-04-08) <= 0 and DATEDIFF(day,pl_dt,2008-04-16) <= 0我们来看看语法:
    DATEDIFF ( datepart , startdate , enddate )
    startdate 是从 enddate 减去。如果 startdate 比 enddate 晚,返回负值。pl_dt=“2008-4-10 9:54:30”
    请看第一个查询条件“2008-4-10”比“2008-04-08”晚吧,返回负值,对的。
    请看第二个查询条件“2008-4-10”比“2008-04-16”晚吗?
    为什么还是返回负值呢?