日期:2014-05-18  浏览次数:20523 次

SQL查询语句,条件无效(添加条件跟无条件是一个结果)
SQL code
SELECT   * FROM         dingdan
WHERE     (arrivaltime <= '2012-05-18')

SELECT   * FROM         dingdan
这个两个语句查询的结果是一样的,实际上,符合条件arrivaltime <= '2012-05-18'的只有一条。 arrivaltime的类型为varchar ,我另外一个查询语句,条件比较复杂 (arrivaltime <= '2012-05-18') AND (lefttime >= '2012-05-18') AND (lefttime <= '2012-05-19') OR
  (arrivaltime >= '2012-05-18') AND (lefttime >= '2012-05-19') AND (arrivaltime < '2012-05-19'),这个都能查询出对的结果。请问各位这是哪里的问题。

------解决方案--------------------
SQL code

SELECT   * FROM         dingdan
WHERE    convert(datetiem,arrivaltime,120)<= '2012-05-18'

------解决方案--------------------
SQL code
SELECT   * FROM         dingdan
WHERE    convert(varchar(10),arrivaltime,120)<= '2012-05-18'

------解决方案--------------------
SQL code
SELECT   * FROM         dingdan
WHERE    convert(varchar(10),arrivaltime,120)<= '2012-05-18'