数据库是access,有个字段是文本型的,但它记录的是日期,现在我想查2005年8月1日至2005年8月11日的数据,sql语句应该怎么写啊?

解决方案 »

  1.   

    为什么不设置成DateTime类型?
      

  2.   

    select * from tableName where txtDate between '2005-8-1' and '2005-8-11' 
    应该还是可以的
      

  3.   

    应该要转换成时间型才能比较的,sqlSelectCommand2.Parameters["@chtyrq"].Value=System.Convert.ToDateTime(this.TextBox1.Text.ToString().Trim());
      

  4.   

    select * from tableName where txtDate between '2005-8-1' and '2005-8-11' 
      

  5.   

    select * from tableName where txtDate between '2005-8-1' and '2005-8-11'这样当然不行了,按字符串,‘2005-8-11'和'2005-8-8'哪个大?如果数据库可以修改,如果你能保证txtDate字段的文本都能转换为时间类型,直接打开Access在表设计器中将textDate字段的类型改为时间类型就可以了。
      

  6.   

    SELECT * FROM [table] where CDate(ReplyDate)>=#2005-8-1# and CDate(ReplyDate)<=#2005-8-11#
    这里的ReplyDate字段可以是中文,比如'2005年8月9日'不过建议还是改成Date类型,一个Bug越早被解决所付出的代价越小
      

  7.   

    to fancyf(凡瑞)
    Sql Server附带Books Online, Access有没有类似的文档?