空不选择列表中的SQL Server 2008

问题描述:

有与结构如下图所示的表格中被选中。该表包含NULL空不选择列表中的SQL Server 2008

enter image description here

正在使用的查询选择NULL

查询#1

select * from table where items1 = 'NULL' 

查询#2

Select * from table where items2 like '%NULL%' 

但是,既没有的查询返回宁任何行!

+0

看来你有一些回答你的问题。我强烈建议你对正常化进行一些阅读和研究。当你需要ITEMS3时你打算做什么? – 2014-10-30 15:40:50

只能使用IS NULLIS NOT NULL的值比较NULL,像这样:

select * from table where items1 IS NULL 

你可以改变一点点的行为,但不推荐。欲了解更多ifnormation看到SET ANSI_NULLS docs

你做不到,你尝试过什么不设置SET ANSI_NULLS OFF。因为NULL在任何数据库中都是不同的东西。任何与NULL变为NULL

如。

select NULL + 1 -- OUTPUT : NULL 
select NULL + 'test' -- OUTPUT : NULL 

即使NULL返回FALSE

如。

select case when NULL=1 then 0 else 1 end -- return false hence 1 

select case when NULL=0 then 1 else 0 end -- return false hence 0 

试试这个:

select * from table where items1 is NULL 

编辑:

SET ANSI_NULLS OFF 

select * from table where items1=null 
+0

这是不准确:如果你设置'ANSI_NULLS'到'OFF'你的答案就完全错误的。 – JotaBe 2014-10-30 15:28:52

+0

@JotaBe谢谢...你有帮助刚才读取和更新 – 2014-10-30 15:37:14