'select * from '''+MReportForm.ARTable+''' where DepName in ('''+SDep+''') order by..... '

解决方案 »

  1.   

    按你的意思,只能对SDep进行分解,最后组成以下形式:
    select * from YourTable where DepName in ('AB','BC','CC','DD') order by DepName
      

  2.   

    DepName in ['AB','BC','CC','DD']
      

  3.   

    可是SDep部门个数不确定,怎么分?怎么写到Sql语句中去?分不够可以再加
      

  4.   

    还有sql语句好像还不认('AB','BC','CC','DD') 的括号
      

  5.   

    一个字符串不能用in啊,看一看wbamboo(波波)的
      

  6.   

    1.SQL.Add('select * from '+MReportForm.ARTable+' where DepName like('+SDep+') order by DepName');由于SDep里面有,分开,你可以直接用like2.自己将SDep进行拆开,然后将它组合成'AB','BC','CC','DD'
      

  7.   

    改写step
    functuion(step:string):Newstep;
    var 
      len,len1,len2,i,j:integer;
      temp1,temp2:string; 
    begin
      len:=length(step);
      len2:=0;
      temp2:=step;
      for i:=0 to len-1 do 
      begin 
        len1:=pos(step,',');
        if len1>0 then
        begin
          temp1:=copy(step,len2+1,len1-1);
          step:=copy(step,len1+1,len-1);
          if length(result) >0 then
            result:= result+','+quoted(temp1);
          else result := qutoted(temp1);
        end;
      end;
    end;
    然后你就可以向你那样写了
      

  8.   

    'select * from '+MReportForm.ARTable+' where ' + SDep + ' like ''%'' || DepName || ''%'' order by DepName'
      

  9.   

    SQL.Add('select * from '+MReportForm.ARTable+' where DepName in ('+SDep+') order by DepName');改为:
    SQL.Add('select * from '+MReportForm.ARTable+' where DepName in ('''+SDep+''') order by DepName');