在listbox中有以下列表
a>=10
and
b<=20
or
c<5
and
d<5如何把这个列表中的内容编程一句符合语法的SQL程序
象 select e from data where ((( a>=10 and b<=20 ) or c<5 ) and d<5 )希望大家帮忙!!!

解决方案 »

  1.   

    select e from data where ((a>=10) and (b<=20)) or ((c<5) and (d<5))
    select e from data where (a>=10) and ((b<=20) or (c<5)) and (d<5)你到底要哪种写法?
      

  2.   

    先判断什么情况下使用,你的没法写,向下面的就可以写
    a>=10
    or
    b<=20
    and
    c<5
    or
    d<5select e from data where ((a>=10) or (b<=20)) and ((c<5) or (d<5))
      

  3.   

    这样写:procedure TForm1.Button1Click(Sender: TObject);
    var
      i: integer;
      str: string;
    begin
      for i := 0 to ListBox1.Items.Count -1 do
      begin
        if ListBox1.Selected[i] then
          str := str +' ' +ListBox1.items[i]
      end;
      with ADOQuery1 do
      begin
        Close;
    ......
        SQL.Add('select e from data where ' +str); 
        Open;
    ......    
      end;  
    end;
      

  4.   

    //Str就是你要的查询字符串了
    procedure TForm1.Button1Click(Sender: TObject);
    var
      i, j, c: integer;
      str: string;
    begin
      str := '';
      i := 0;
      for i:=ListBox1.Items.Count-1 downto 1 do
      begin
        if (j mod 2)=0 then
        begin
          if ListBox1.Items[i]<>'' then
          begin
            str := ListBox1.Items[i]+')'+str;
            c := c+1;
          end;
        end
        else
          str := ListBox1.Items[i]+' '+str;
        j := j+1;
      end;
      str := ListBox1.Items[0]+' '+str;
      for i:=0 to c-1 do
        str := '('+str;
      Memo1.Lines.Add(str);
    end;
      

  5.   

    不好意思!
    实现的写法是:select e from data where ((a>=10) and (b<=20)) or ((c<5) and (d<5))
    或                                      ((a>=10) and (b<=20) or (c<5)) and (d<5)在listbox中提取这样顺序的条件
    如果出现
    a>=10
    or
    b<=20
    and
    c<5
    d<5
    or 的情况可以判断查询条件出错!!!
      

  6.   

    先把ListBox的内容以文本文件的形式导出!再进行处理!
    有问题请发信息到我的E-mail:[email protected]
      

  7.   

    我觉得"or"和"and"这两个符号由程序自行加入,这样可以避免错误,例如:
    a>=10
    or b<=20
    and c<5
    or d<5除了对第一个元素进行处理的时候要注意一些
      

  8.   

    取得到listbox中的值在复入sql语句中就可以了