我在查询时间取2012-05-07至2012-05-19的时间信息,却取出了两条4月19日的信息,
student 表数据如下
id name sub_time
1   张三 2012-04-19 17:19:57.660
2   李四 2012-04-19 17:31:44.700
3   董莉 2012-05-17 19:08:10.260
4   莫小三  2012-05-19 10:06:11.363
查询语句
select * from student
where convert(varchar(12),res_subdate,105) between '17-05-2012' and '19-05-2012';
查询结果集里却出现了张三和李四的记录。。很纳闷,向高手们请教了。

解决方案 »

  1.   

    select * from student
    where sub_time  between '17-05-2012' and '19-05-2012';
      

  2.   

    select * from student
    where sub_time between '2012-05-07' and '2012-05-19';
    要写时间就好好写,干嘛要反过来,不学好
      

  3.   

    select * from student
    where convert(varchar(10),res_subdate,120) between '2012-05-07' and '2012-05-19';
      

  4.   


    正确写法:
    select * from student
    where convert(varchar(10),res_subdate,120) between '2012-05-07' and '2012-05-19';
      

  5.   

    你表里的字段名字叫sub_time,语句里又是res_subdate,好乱啊