不等于(<>)访问SQL

时间:2013-12-03 20:45:01

标签: sql ms-access where sql-delete

我怎么写:

DoCmd.RunSQL "DELETE FROM tblB WHERE [Field1]) <> 'YES' "

写作时发现了3条记录:

DoCmd.RunSQL "DELETE FROM tblB WHERE [Field1]) = 'YES' "

我假设如果字段为空,则验证条件

“~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~

感谢您的建议。我不得不使用IS NULL

DoCmd.RunSQL "DELETE FROM tblB WHERE [Field1] IS NULL"

1 个答案:

答案 0 :(得分:1)

如果您的目标是删除[Field1] <> 'YES'的所有行,包括[Field1] Is Null的行,则可以在WHERE子句中添加其他条件。

DoCmd.RunSQL "DELETE FROM tblB WHERE [Field1] <> 'YES'" & _
    " OR [Field1] Is Null"

或者您可以在单个`WHERE条件中使用Nz函数。

DoCmd.RunSQL "DELETE FROM tblB WHERE Nz([Field1], '') <> 'YES'"