procedure TForm1.Button1Click(Sender: TObject);
var
s,t:string;
begin
if checkbox1.Checked then
begin
s:=edit1.Text;
oraquery1.Close;
oraquery1.SQL.Text:='select a.personid,a.hname,b.hname,a.recordtime from y_jcyy_logpeccancy a ,j_jcyy_peccancytype b where a.peccancytypeid = b.id and a.personid='''+s+'''';
oraquery1.Open;
end;
if checkbox2.Checked then
begin
s:=edit2.Text;
oraquery1.Close;
oraquery1.SQL.Text:='select a.personid,a.hname,b.hname,a.recordtime from y_jcyy_logpeccancy a ,j_jcyy_peccancytype b where a.peccancytypeid = b.id and a.hname like'''+s+'''';
oraquery1.Open ;
end;
if checkbox1.Checked and checkbox2.Checked then
begin
s:=edit1.Text;
t:=edit2.Text;
oraquery1.Close;
oraquery1.SQL.Text:='select a.personid,a.hname,b.hname,a.recordtime from y_jcyy_logpeccancy a ,j_jcyy_peccancytype b where a.peccancytypeid = b.id and (a.hname ='''+t+''') and (a.personid='''+s+''')';
oraquery1.Open;
end;
if checkbox3.Checked then
begin
oraquery1.Close;
oraquery1.SQL.Text:='select a.personid,a.hname,b.hname,a.recordtime from y_jcyy_logpeccancy a ,j_jcyy_peccancytype b where a.peccancytypeid = b.id and (b.hname ='''+combobox1.Text+''')';
oraquery1.Open;
end;
end;

解决方案 »

  1.   

    感觉可以类似这样 把SQL相同的部分提出来,看起来就清爽多了
      with oraquery1 do
      begin
        Close;
        SQL.Text:='select a.personid,a.hname,b.hname,a.recordtime from  y_jcyy_logpeccancya ,
          j_jcyy_peccancytype b where a.peccancytypeid = b.id and '''+s+''' ';
      end;if checkbox1.Checked then 
    begin 
    s:='a.personid='+edit1.Text; 
    oraquery1.Close;
    oraquery1.Open; 
    end; 
                            
      

  2.   


    procedure TForm1.Button1Click(Sender: TObject);
    var
        s,t,s2:string;
    begin
        oraquery1.Close;
        if checkbox1.Checked then
        begin
            s:=edit1.Text;
            s2:=' and a.personid='''+s+'''';
        end;
        if checkbox2.Checked then
        begin
            s:=edit2.Text;
            s2:=' and a.hname like'''+s+'''';
        end;
        if checkbox1.Checked and checkbox2.Checked then
        begin
            s:=edit1.Text;
            t:=edit2.Text;
            s2:=' and (a.hname ='''+t+''') and (a.personid='''+s+''')';
        end;
        if checkbox3.Checked then
        begin
            s2:=' and (b.hname ='''+combobox1.Text+''')';
        end;    oraquery1.SQL.Text:='select a.personid,a.hname,b.hname,a.recordtime from y_jcyy_logpeccancy a ,j_jcyy_peccancytype b where a.peccancytypeid = b.id '+s2;
        oraquery1.Open;
    end;