只返回空字段的行?

Mik*_*k0r 3 sql ms-access

我有一个表,其中一个字段可以为空.我试图只返回这个字段为空的行.但是我一直在做WHERE field =""...... WHERE field =''...... WHERE field = null

我缺少什么想法?

Lar*_*tig 13

In SQL, a completely empty field is said to be NULL. For NULL searches you do not use equals (=), but rather the special operator IS NULL:

 SELECT * FROM table WHERE field IS NULL
Run Code Online (Sandbox Code Playgroud)

Access allows you to have not NULL empty fields if you allow empty strings, this is a bad idea as it makes it difficult to distinguish visual between a NULL value and a 0-length string, so I suggest you don't permit it in your database.

  • 空间填充和零长度的字符串是可能的,因此要覆盖所有基础,您可以使用修剪(字段&"")="". (3认同)
  • 我会接受长度为0的字符串为空,但就我个人而言,我不会将带空格的字符串视为空。无论如何,从这个问题来看,我很确定OP的问题不是标识不同类型的空字符串,而是不知道IS NULL运算符。 (2认同)