Home > Topics > Access > body text

access delete empty field records

王林
Release: 2020-12-01 15:46:57
forward
3446 people have browsed it

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;
Copy after login

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;
Copy after login

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!

Related labels:
source:csdn.net
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!