客户一个数据库表中一列为[DateAndTime],但却为文本类型。日期格式为2010年09月12日。我想实现日期的区间选择, select XXXX from xxxx where DateAndTime between 2010年09月12日 and 2010年10月01日。没效。该怎么办?  (表格中平均每个相同的日期占10行左右,即是每个日期的id不是唯一的,但我只根据日期区间选择)

解决方案 »

  1.   

     select XXXX from xxxx where DateAndTime between 
    Convert(datetime, '2010年09月12日',  120) 
     and  Convert(datetime, '2010年10月01日',  120) 主要就是 先把字符串类型的转换成 日期类型  再查询大概是这个思路 
      

  2.   

    select XXXX from xxxx where DateAndTime between 
     cdate('2010年09月12日')
      and  cdate( '2010年10月01日') 试试这个
      

  3.   

    select * from XXXX  where to_date(replace(replace(replace(DateAndTime ,'年','-'),'月','-'),'日',''),'yyyy-mm-dd') > to_date('2010-09-12','yyyy-mm-dd')and to_date(replace(replace(replace(DateAndTime ,'年','-'),'月','-'),'日',''),'yyyy-mm-dd')<to_date('2010-10-01','yyyy-mm-dd')
      

  4.   

    不用这么复杂。 你这种情况 直接用between and就行了。 假设d1为你的起始日期:2013年02月28日,d2为介绍日期:2013年03月01日,"select....between" +d1+" and"+ d2.就可以了。注意d1与d2日期格式相同。
    给你感受下。