2014-10-30 38 views
-2

有與結構如下圖所示的表格中被選中。該表包含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

回答

2

只能使用IS NULLIS NOT NULL的值比較NULL,像這樣:

select * from table where items1 IS NULL 

你可以改變一點點的行爲,但不推薦。欲瞭解更多ifnormation看到SET ANSI_NULLS docs

2

你做不到,你嘗試過什麼不設置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