with adrqMeterData do
try
  SQL.Text := 'select * from where todaytime between '
    + ':startdayvalue and :enddayvalue';
  Parameters.ParamByName('startdayvalue').Value := dtpStartDate.Date;
  Parameters.ParamByName('enddayvalue').Value := dtpEndDate.Date;
  ExecSQL;
except

end;
todaytime 是一个datatime字段,
这是一个日期比较查询语句,但是F9的时候出错,提示在关健字where边上有语法错误,我知道这种写法有点问题,但是不知道怎么修改。

解决方案 »

  1.   

    从哪个表查啊?elect * from where ****表名字呢?**** todaytime 
      

  2.   


    select * from 表名字 where todaytime between 
      

  3.   

    select * from 表名 where
      

  4.   

    用Formatdatetime格式化一下日期再做查询
      

  5.   

    汗一个,是我忘了写表名了,但是还有个问题,这样查不出数据来,实际上表里有数据的,我想问题应该在时间比较语句里,我想把startdayvalue这里用dtpStartDate的年月日,但是Time改为00:00:00,enddayvalue改为dtpEndDate的年月日,但是Timen改为24:00:00,我的写法:
        Parameters.ParamByName('startdayvalue').Value := FormatDateTime('yyyy-mm-dd 00:00:00', dtpStartDate.Date);
        Parameters.ParamByName('enddayvalue').Value := FormatDateTime('yyyy-mm-dd 24:00:00', dtpEndDate.Date);
    但是F9出错,提示:应用程序在当前操作使用了错误类型值:(
      

  6.   


    Parameters.ParamByName('enddayvalue').Value := FormatDateTime('yyyy-mm-dd 23:59:59', dtpEndDate.Date); 
      

  7.   

    楼上的写法好象也不对吧,我已经改了语句为:
    Parameters.ParamByName('startdayvalue').Value := strtodate(FormatDateTime('yyyy-mm-dd 00:00:00', dtpStartDate.Date));
    Parameters.ParamByName('enddayvalue').Value := strtodate(FormatDateTime('yyyy-mm-dd 23:59:59', dtpEndDate.Date));
    F9的结果提示:'2009-01-06 00:00:00' is not a valid date
      

  8.   

    formatdatetime('yyyy-mm-dd',dtpStartDate.Date)
      

  9.   

    终于搞定了,谢谢各位,正确的写法应该是这样:
    Parameters.ParamByName('startdayvalue').Value := StrToDateTime(FormatDateTime('yyyy-mm-dd 00:00:00', dtpStartDate.Date)); 
    Parameters.ParamByName('enddayvalue').Value := StrToDateTime(FormatDateTime('yyyy-mm-dd 23:59:59', dtpEndDate.Date));