var
s1,s2,s3,sql3,Str_Result:string;
begin
Str_Result:='';
s1:=trim(Edit1.Text);
s2:=trim(Edit2.Text);
s3:=trim(Edit2.Text);
s3:=copy(s3,1,4);
sql3:='select 标题,摘要,来文单位,收到日期,文件字号,档号 from mfile';if (Length(Trim(Edit1.Text))<>0) then
  Str_Result:=' where 标题 like '+'%'+s1+'%';  if (Length(Trim(Edit2.Text))<>0) then
  begin
       if Str_Result='' then
         Str_Result:=' where 摘要 like '+'%'+s2+'%'
       else
         Str_Result:=Str_Result+' and 摘要 like '+'%'+s2+'%';
  end;  if (Length(Trim(Edit3.Text))<>0) then
    begin
      if Str_Result ='' then
        Str_Result:=' where 日期='+s3+'%'
      else
         Str_Result:=Str_Result+' and 日期 like '+s3+'%';
    end;
sql3:=sql3+Str_Result;
RunSQL(ADOQuery2,sql3,0);

解决方案 »

  1.   

    其中 标题,摘要是文本型
    日期为日期/时间型
    在DELPHI6中执行出现的错误如下
    在三个文本框中无论输入哪个都报
    [microsoft][ODBC Microsoft Access Driver]语法错误,在查询表达式'标题 lik %广东%'中
    请高手给予帮助,提出正确的写法.
      

  2.   

    应该写为 标题 like '''+'%'+s1+'%'+'''
      

  3.   

    ''' and 日期 like '''+s3+'''%'''';
      

  4.   

    if (Length(Trim(Edit2.Text))<>0) then
      begin
           if Str_Result='' then
             Str_Result:=Format(' where 摘要 like ''%%%s%%''',[s2])
           else
             Str_Result:=Str_Result+Format(' and 摘要 like ''%%%s%%''',[s2]);
      end;  if (Length(Trim(Edit3.Text))<>0) then
        begin
          if Str_Result ='' then
            Str_Result:=Format(' where 日期=#%s#',[s3])
          else
             Str_Result:=Str_Result+Format(' and 日期 like #%s#',[s3]);
        end;