在 sql 中选择 NULL 和 false 但不是 true
我是 vb.ner sql 中的一个新人,我问的可能是愚蠢的问题.我在 sql server 2005 中有一个表,并激活了一个列名.此列包含 NULL、true 或 false.
i an new in vb.ner sql and what i am asking may be silly question. I have a table in sql server 2005 and a column name activated. this column contain NULL, true or false.
我只想选择 NULL 或 false 值.我怎样才能做到这一点?
I want to select only NULL or false values. How can i do this?
推荐答案
选择应该在 SQL Server 一侧完成.您的查询应如下所示:
The selection should be done on the SQL Server's side. Your query should look like this:
SELECT *
FROM MyTable
WHERE activated = 0 OR activated is NULL
以上假设列 activated
是整数或 BIT
数据类型.
The above assumes that the column activated
is of an integral or a BIT
data type.
注意:使用看似等效的 WHERE 激活 <> 可能很诱人.1
条件.但是,这是不正确的,因为将 NULL
值与任何值进行比较会导致 NULL
,因此将排除具有 activated = NULL
的行.
Note: it may be tempting to use a seemingly equivalent WHERE activated <> 1
condition. This would be incorrect, though, because comparisons of NULL
values to anything result in a NULL
, so the rows with activated = NULL
would be excluded.
相关文章