First of all, we need to know that null and empty string are different in Access, so if this problem is not handled well, it will cause a lot of trouble, especially in mixed queries.
(Recommended tutorial: access database learning)
The solution is as follows:
var SQLStr:string; begin // SQLStr := 'select * from ordertb where 1>0'; if Trim(Edit1.Text)<>'' then SQLStr := SQLStr +' and serialid like :a'; if Trim(Edit2.Text)<>'' then SQLStr := SQLStr +' and pname like :b'; with ADOQuery1 do begin Close; SQL.Clear; SQL.Add(SQLStr); if Trim(Edit1.Text)<>'' then Parameters.ParamByName('a').Value := '%'+Trim(Edit1.Text)+'%'; if Trim(Edit2.Text)<>''then Parameters.ParamByName('b').Value := '%'+Trim(Edit2.Text)+'%'; Open; end; end;
or:
begin with ADOQuery1 do begin Close; SQL.Clear; SQL.Add('select * from ordertb where 1>0'); if Trim(Edit1.Text)<>'' then SQL.Add(' and serialid like ''%'+Trim(Edit1.Text)+'%'''); if Trim(Edit2.Text)<>''then SQL.Add(' and pname like ''%'+Trim(Edit2.Text)+'%'''); Open; end; end;
Summary :
Filter out fields with empty conditions from the query statement.
The above is the detailed content of access delete empty field records. For more information, please follow other related articles on the PHP Chinese website!