SQL语句问题,怎么查结果都一样
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
[解决办法]
select *from DQ_Rp_Plan_Houseitemwhere 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_Houseitemwhere 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_Houseitemwhere 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_Houseitemwhere 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的范围内,条件不成立,所以表里面的内容查不出来
[解决办法]