select *
from DQ_Rp_Plan_Houseitem
where datediff(dd,cast('2012-04-12' as datetime),cast('2012-04-15' as datetime)) between 1 and 5和
select *
from DQ_Rp_Plan_Houseitem
where datediff(dd,cast('2012-04-12' as datetime),cast('2012-04-19' as datetime)) between 1 and 5和select *
from DQ_Rp_Plan_Houseitem
where datediff(dd,cast('2012-04-12' as datetime),cast('2012-04-15' as datetime)) between 1 and 10
怎么查结果都一样 结果都是数据表里的全部数据 没有 按指定时间显示哪里的问题?数据库的 日期字段 为字符串型的 vchar--------------------------------------------------但如果用SQL code
select *
from DQ_Rp_Plan_Houseitem
where datediff(dd,cast('2012-04-12' as datetime),getdate()) between 1 and 5
 
 
 
不提示错误 但会没有结果 

解决方案 »

  1.   

    select *
    from DQ_Rp_Plan_Houseitem
    where datediff(dd,cast('2012-04-12' as datetime),cast('2012-04-19' as datetime)) between 1 and 5这个绝对是没有数据的。
      

  2.   

    select *
    from DQ_Rp_Plan_Houseitem
    where datediff(dd,cast('2012-04-12' as datetime),cast('2012-04-15' as datetime)) between 1 and 5where语句为true,返回的肯定是select * from DQ_Rp_Plan_Houseitem 的所有数据换成select *
    from DQ_Rp_Plan_Houseitem
    where datediff(dd,cast('2012-04-12' as datetime),数据库中的时间字段) between 1 and 5
      

  3.   

    print datediff(dd,cast('2012-04-12' as datetime),cast('2012-04-19' as datetime))
    print datediff(dd,cast('2012-04-12' as datetime),cast('2012-04-15' as datetime))
    结合结果,看下你的where条件
      

  4.   

    1.检查下查询条件
    2.datediff 里面的值 是不是匹配的有数据