select * from table1 where dtt>='2002-2-1 12:00:00' and dtt<='2002-2-1 18:00:00'
或者
select * from table1 where dtt between '2002-2-1 12:00:00' and '2002-2-1 18:00:00'

解决方案 »

  1.   

    用最新sql来写,只要是关系数据库都支持,但不要用扩展语句!
    dtStart:='2002-2-1 12:00:00';
    dtEnd:='2002-2-1 18:00:00';
    sqltxt:='select * from table1 where 
                  '(dtt>'''+datetimetostr(dtend)+'''' 
                   ') and (dtt <'''+datetimetostr(dtstart)+''')')
      

  2.   

    你要记住!你传给dbms的东西(sql)必须是字符串!例如你要查找!
    名字为“xxx"的人
    sql :select * from man where Name='xxx'
    在delphi:
    中写为:
    commandText:='select * from man where Name='+''''+'xxx'+'''';
    dbms接收到的东西为:select * from man where Name='xxx';
    主要是为了保证传给dbms的东西是你想传的东西
      

  3.   

    兄弟帮个忙http://www.csdn.net/expert/topic/594/594397.xml?temp=.8597986
      

  4.   

    对于时间必须要用参数,负责查询结果为空,方法如下:
    query1.sql:='select * from man where bir>=:date1 and Bir<=;date2';
    query1.params.param('date1'):=*******;
    query1.params.param('date2'):=*******;
    query1.open;
      

  5.   

    我调试过,传给commandtext的sql语句是这样的
    ‘select * from myTable where dtt<='2002-1-1 13:00:00' and 
    dtt>='2002-1-1 6:00:00' ’;
    在执行ClientDataset.open语句的时候,出错提示信息为‘标准表达式中类型不匹配’。不只是何道理?
      

  6.   

    我对ClientDataset.filter属性进行设置的时候
    ClientDataset.filter:='dtt <= '''+datetimetostr(dtend)+''''+
            ' and dtt <='''+datetimetostr(dtstart)+'''';是没问题的。
    我认为filter也是sql,但为何两者本质一样,语句一样,但执行起来,commandtext就不能正常执行呢