用静态写好sql:='select * from table where f1 in ('a','b','c')';
运行一切正常.
但用动态生成一模一样的sql语句只能选出f1=a的记录,不知道为什么??

解决方案 »

  1.   

    不会吧,动态生成sql的代码给出来看看
      

  2.   

    with ADOQuery1 do
      begin
        close;
        sql.Clear;
        SQL.Add('select * from table where 1=1');    if trim(edit1.text) <> '' then
      //*********读取字符串进数组*************
          theStr := trim(edit1.Text);
        nStartPos := 1;
        nEndPos := Pos(',', theStr);
        i := 1;
        while nEndPos > 0 do
        begin
          a[i] := MidStr(theStr, nStartPos, nEndPos - nStartPos);
          theStr[nEndPos] := ' ';
          nStartPos := nEndPos;
          nEndPos := Pos(',', theStr);
          inc(i);
        end;
      //**************读取结束*************    if i > 1 then
        begin
          sql.add(' and f1 in');
          for j := 1 to i - 1 do
          begin
            sqlstr := sqlstr + '''' + a[j] + ''',';
          end;
          sqlstr := '(' + leftstr(sqlstr, length(sqlstr) - 1) + ')';
        end;
        SQL.add(sqlstr);
      end;
      

  3.   

    edit1.text的内容也是动态生成的
    如a,b,c,d,……
      

  4.   

    adoquery1.Close;
    adoquery1.SQL.clear;
    adoquery1.sql.Add('select * from AST_BillType where vchr_BillTypeID in ('+'''a'''+','+'''b'''+','+'''c'''+')');
     adoquery1.Active :=true ;
      

  5.   

    select * from table where f1 in ('a','b','c')
    是动态生成最后执行前的语句,我用showmessage(sql.text)查看过,动态和静态完全相同,但执行结束就是只能执行f1=a(a是in 后面的第一项)
      

  6.   

    应该这样:
        theStr := trim(edit1.Text);
        nStartPos := 1;
        nEndPos := Pos(',', theStr);
        i:=1;
        while nEndPos > 0 do
        begin
          a[i] := copy(theStr, 1, nEndPos - 1);
          theStr:=copy(theStr,nEndPos+1,length(theStr)-nEndPos);
          nEndPos := Pos(',', theStr);
          inc(i);
        end;
        a[i]:=theStr;
      

  7.   

    你的SQL 语句执行的效果,等同于执行了一次打开操作(open),故只返回最后一次条件的结果集
      

  8.   

    用这个试试 fl='a' or fl='b' or fl='c'