我在delphi中使用了edit、adoquery、dbgrid,链接informix库.请问这个语句在delphi中应该怎样写,多谢!select 编码,名称,售价
from 资料表
into temp A1;   //为了提高速度我建了一个临时表select a.编码,a.名称,b.数量,b.进价
from A1 a,订单表 b
where a.编码=b.编码
and a.编码 in (001,002,.....)   //括号内的编码由用户在edit中输入.
order by 1 

解决方案 »

  1.   

    用户在一个Edit里输入
    001,002,.....信息吗?
      

  2.   

    and a.编码 in (001,002,.....)   //括号内的编码由用户在edit中输入. 
    ???????????逗号也输入么?adoQuery1.Sql.Clear;
    adoQuery1.Sql.Add('select a.编码,a.名称,b.数量,b.进价 from A1 a,订单表 b where a.编码=b.编码 ');
    adoQuery1.Sql.Add('and a.编码 in ('+Edit1.Text+')');   //括号内的编码由用户在edit中输入. 
    adoQuery1.Sql.Add('order by 1  ');
      

  3.   

    2楼的写法我试了一下,delphi报   ')'附近有语法错误
      

  4.   

    1、Edit输入的时候,最后有个',' ?2、确认是 in(001,002,.....) ,不是in ('001','002',...)么?
      

  5.   

    要解析并转化Edit里的内容,用以下函数:function GetLinkedCode(S: String): String;
    var
      Sub: String;
      i: Integer;
    begin
      Result := '';
      while S <> '' do
      begin
        i := Pos(',', S);
        if i = 0 then
        begin
          Sub := Trim(S);
          S := '';
        end
        else
        begin
          Sub := Trim(Copy(S, 1, i - 1));
          S := Copy(S, i + 1, Length(S) -i);//余下部分
        end;    if Sub <> '' then
        begin
          if Result = '' then
             Result :=  QuotedStr(Sub)
           else
             Result := Result + ',' + QuotedStr(Sub);
        end;
      end;
      if Result = '' then
        Result := QuotedStr('');
    end;调用时:  ADOQuery1.Close;
      ADOQuery1.Sql.Clear;
      ADOQuery1.Sql.Add('select a.编码,a.名称,b.数量,b.进价 from A1 a,订单表 b where a.编码=b.编码 ');
      //括号内的编码转化为带'号以逗号分割的串.
      ADOQuery1.Sql.Add('and a.编码 in (' + GetLinkedCode(Edit1.Text) + ')');
      ADOQuery1.Sql.Add('order by 1  ');
      

  6.   

    调试一下,跟踪到adoQuery1.Open;看一下adoQuery1.Sql.Text内容,拷贝到Sql 查询分析器能得到结果不,就知道哪里有问题了。