with mydata.ADOQemployee do
    begin
      close;
      sql.Clear;
      sql.add('select * from v_employee where (name is not null)');      if s_date_check.checked=false then
        begin
          sql.Add(' and inday >=:fromday and inday<:today');
          decodedate(dtp_from.Date,v_year,v_month,v_day);
          v_datefrom:=strtodate(inttostr(v_year) + '-' + inttostr(v_month) + '-' + inttostr(v_day));
          decodedate(dtp_to.Date+1,v_year,v_month,v_day);
          v_dateto:=strtodate(inttostr(v_year) + '-' + inttostr(v_month) + '-' + inttostr(v_day));
          parameters.ParamByName('fromday').Value:=v_datefrom;
          parameters.ParamByName('today').Value:=v_dateto;
        end;
      open;
  end;上面这段语句是查询一段日期内的员工,但是老是说“ODBC SQL SERVER DRIVER 没有执行可选特性”,请各位帮帮忙,实在是没有办法了。

解决方案 »

  1.   

    改为
    ' and inday >= '+ QuotedStr(FormatDateTime('yyyy-mm-dd',dtp_from.Date))+' and inday<' + QuotedStr(FormatDateTime('yyyy-mm-dd',dtp_to.Date+1));
      

  2.   

    记住, 在日期在作为条件要把它当成字符串处理, 要把日期格式化一下,
    我这种方式很方便调试, 我都很少用参数
    FormDateTime('yyyy-mm-dd', Date);
    var
      strSQL: string;
    begin
      with mydata.ADOQemployee do  begin
        close;
        sql.Clear;
      strSQL := 'select * from v_employee where (name is not null) and inday>=''%s'' and inday<''%s''';
      strSQL := Format(strSQL, [FormDateTime('yyyy-mm-dd', dtp_from.Date), FormDateTime('yyyy-mm-dd', dtp_to.Date)]);
      SQL.Text := strSQL;
      Open;
     end;
      
      
      

  3.   

    inday字段是date还是timestamp类型,可能是这个原因
    用楼上不用参数直接传字符串的办法试一下,还不对的话把SQL语句取出来到查询分析器里试一下
      

  4.   

    如果inday字段是datetime类型,
          if s_date_check.checked=false then
            begin
              sql.Add(' and inday >=:fromday and inday<:today');
              parameters.ParamByName('fromday').Value:=dtp_to.Date;
              parameters.ParamByName('today').Value:=dtp_to.Date+1;
            end;
          open;
    如果inday字段是char类型
          if s_date_check.checked=false then
            begin
              sql.Add(' and inday >=:fromday and inday<:today');
              decodedate(dtp_from.Date,v_year,v_month,v_day);
              v_datefrom:=inttostr(v_year) + '-' + inttostr(v_month) + '-' + inttostr(v_day));
              decodedate(dtp_to.Date+1,v_year,v_month,v_day);
              v_dateto:=inttostr(v_year) + '-' + inttostr(v_month) + '-' + inttostr(v_day);
              parameters.ParamByName('fromday').Value:=v_datefrom;
              parameters.ParamByName('today').Value:=v_dateto;
            end;
          open;
      

  5.   

    如果你的inday在数据库中是TDatetime类型的,那这代码应该没问题的。