日期:2014-05-18 浏览次数:20609 次
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 --datediff(dd,cast('2012-04-12' as datetime),cast('2012-04-15' as datetime))=3,3在1和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 --datediff(dd,cast('2012-04-12' as datetime),cast('2012-04-19' as datetime))=7,不在1和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 --datediff(dd,cast('2012-04-12' as datetime),cast('2012-04-15' as datetime))=3,条件成立,返回所有结果
------解决方案--------------------
select * from DQ_Rp_Plan_Houseitem where datediff(dd,cast('2012-04-12' as datetime),getdate()) between 1 and 5 --datediff(dd,cast('2012-04-12' as datetime),getdate())值为17 --不在1到5的范围内,条件不成立,所以表里面的内容查不出来
------解决方案--------------------