2013年2月21日 星期四

腦力退化....null 值比較

今天在informix 做一個簡單的查詢時竟然對這個查詢結果懷疑了起來

create table test(col1 char(1) not null, col2 char(1));

insert into test values ('1' ,null);
insert into test values ('1' ,'1');

select * from test where col2 <> '1' ;

原本以為會回傳第一筆資料. 但卻回傳0筆.

以為是informix才會這樣,結果到sql server也是如此.

我的頭腦真是老化了,怎麼懷疑起這樣的結果呢.

null 與任何值比較應都是無法比的.

欄位值有null先轉型再比較唄

--tsql
select * from test where coalesce(col2,'') <> '1' ;

--informix
select * from test where nvl(col2,'') <> '1' ;


參考NULL 值說明

沒有留言:

張貼留言

publish error allowDefinition='MachineToApplication'

一個老舊的aspx web form專案,調了一些功能建置成功,但進行部署時顯示以下錯誤。 在應用程式層級之外使用註冊為 allowDefinition='MachineToApplication' 的區段發生錯誤。錯誤的原因可能是虛擬目錄尚未在 IIS 中設定為...