我想做合并查询,代码如下: 
  choice:=combobox1.text;
  content:=edit1.Text;
  choice1:=combobox4.Text;
  content1:=edit2.Text;
  adoquery1.Close;
  adoquery1.SQL.Clear;
  adoquery1.SQl.add('select * from xuesheng_table where ('+choice+'               
                    like ''%'+content+'%'')and');
  adoquery1.sql.Add('('+choice1+' like ''%'+content1+'%'')');
  adoquery1.Open;请教下执行的SQL语句错在哪里 (like附近有语法错误)

解决方案 »

  1.   

    看看第一个like前是否留有空格
      

  2.   

    应该留一个空格的,否则字段名choice就和‘like’连在一起了
      

  3.   

    建议lz在调试的时候把SQL语句打印出来不就很明显知道问题了嘛,何必猜测呢
      

  4.   

    是少空格了,这样就可以了
      adoquery1.SQl.add('select * from xuesheng_table where ('+choice+
      ' like ''%'+content+'%'') and ');
      adoquery1.sql.Add('('+choice1+' like ''%'+content1+'%'')');
      

  5.   

    晕,原来是自己第2个combobox没赋初值,只选一个就出错
      

  6.   

    是少空格了,这样就可以了
      adoquery1.SQl.add('select * from xuesheng_table where ('+choice+
      ' like ''%'+content+'%'') and ');
      adoquery1.sql.Add('('+choice1+' like ''%'+content1+'%'')');
      

  7.   

    在那个面板上先
    adoquery1.SQL.Clear;
      adoquery1.SQl.add('select * from xuesheng_table where ('+choice+'               
                        like ''%'+content+'%'')and');
      adoquery1.sql.Add('('+choice1+' like ''%'+content1+'%'')');
        edit1.text:=sql.text;
      //adoquery1.Open;  
     加个EDIT把SQL显示出来, 一看不就明白了.
      

  8.   

    这种情况,最好不用 + 来连接字符串, 可以用 Format来实现。
    adoquery1.SQL.Clear;
      adoquery1.SQl.add(Format('select * from xuesheng_table where ( %s             
                        like '%%s%') and %s like '%%s%')' , choice, content, choice1,content1);
      

  9.   

    adoquery1.SQl.add('select * from xuesheng_table where ('+choice+'               
                        like ''%'+content+'%'')and');
    -------------〉  adoquery1.SQl.add('select * from xuesheng_table where ('+choice+'               
                        like ''%'+content+'%'') and');