Home  >  Article  >  Topics  >  access delete empty field records

access delete empty field records

王林
王林forward
2020-12-01 15:46:573487browse

access delete empty field records

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)<>&#39;&#39; then
  SQLStr := SQLStr +&#39; and serialid like :a&#39;;
  if Trim(Edit2.Text)<>&#39;&#39; then
  SQLStr := SQLStr +&#39; and pname like :b&#39;;
 
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add(SQLStr);
    if Trim(Edit1.Text)<>&#39;&#39; then
    Parameters.ParamByName(&#39;a&#39;).Value := &#39;%&#39;+Trim(Edit1.Text)+&#39;%&#39;;
    if Trim(Edit2.Text)<>&#39;&#39;then
    Parameters.ParamByName(&#39;b&#39;).Value := &#39;%&#39;+Trim(Edit2.Text)+&#39;%&#39;;
    Open;
  end;
end;

or:

begin  
  with ADOQuery1 do
  begin
    Close;
    SQL.Clear;
    SQL.Add(&#39;select * from ordertb where 1>0&#39;);
    if Trim(Edit1.Text)<>&#39;&#39; then
    SQL.Add(&#39; and serialid like &#39;&#39;%&#39;+Trim(Edit1.Text)+&#39;%&#39;&#39;&#39;);
    if Trim(Edit2.Text)<>&#39;&#39;then
    SQL.Add(&#39; and pname like &#39;&#39;%&#39;+Trim(Edit2.Text)+&#39;%&#39;&#39;&#39;);
    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!

Statement:
This article is reproduced at:csdn.net. If there is any infringement, please contact admin@php.cn delete