procedure TForm1.Edit1Change(Sender: TObject);
begin
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select * From ERP '); //Acess数据库中表的名字为“ERP”
if (Edit1.Text <> '') and (Edit2.Text <> '') then
begin
ADOQuery1.SQL.Add(' where 存货编码 like :strP1 and (存货名称 like :strP2 or 规格型号 like :strP3) and not (优选等级 like :strP4)');
ADOQuery1.Parameters.ParamByName('strP1').Value := Edit1.Text + '%';
ADOQuery1.Parameters.ParamByName('strP2').Value := '%' + Edit2.Text + '%';
ADOQuery1.Parameters.ParamByName('strP3').Value := '%' + Edit2.Text + '%';
ADOQuery1.Parameters.ParamByName('strP4').Value := '%D%';
end;
if (Edit1.Text <> '') and (Edit2.Text = '') then
begin
ADOQuery1.SQL.Add(' where 存货编码 like :strP1 and not (优选等级 like :strP4)');
ADOQuery1.Parameters.ParamByName('strP1').Value := Edit1.Text + '%';
ADOQuery1.Parameters.ParamByName('strP4').Value := '%D%';
end;
if (Edit1.Text = '') and (Edit2.Text <> '') then
begin
ADOQuery1.SQL.Add(' where (存货名称 like :strP2 or 规格型号 like :strP3) and not (优选等级 like :strP4)');
ADOQuery1.Parameters.ParamByName('strP2').Value := '%' + Edit2.Text + '%';
ADOQuery1.Parameters.ParamByName('strP3').Value := '%' + Edit2.Text + '%';
ADOQuery1.Parameters.ParamByName('strP4').Value := '%D%';
end;
if (Edit1.Text = '') and (Edit2.Text = '') then
begin
ADOQuery1.SQL.Add(' where not (优选等级 like :strP4)');
ADOQuery1.Parameters.ParamByName('strP4').Value := '%D%';
end;
ADOQuery1.SQL.Add(' order by 存货编码 ');
ADOQuery1.Open;
end;