当前位置: 主页 > Office办公 > 其他专区 > Access > access如何删除空字段记录

access如何删除空字段记录

  • 2022-03-25
  • 来源/作者: 菜鸟图库/ 菜鸟图库
  • 377 次浏览

access如何删除空字段记录

 

首先我们需要知道在Access中null和空字符串是不同的,因此如果处理不好该问题就会带来不少麻烦,特别是在混合查询中。

(推荐教程:access数据库学习)

解决方法如下:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

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;

或者:

1

2

3

4

5

6

7

8

9

10

11

12

13

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;

总结:

将条件为空的字段从查询语句中过滤掉。