SQL Server2000
2008年11月6日 お仕事 コメント (2)職場でMicrosoft SQL Server2000を使っています。
今日、この条件でselectできないんだけどという問い合わせがありました。
調査結果としてはプログラムバグに分類されるのですが、いまいち納得できない……
とりあえず、防備録として残しておきます。
select count(*)
from MasterTable
where Code1 = ’A’;
件数:100
select count(*)
from MasterTable
where Code1 = ’A’ and (Code2 = ’AA’ and Val1 = 1000);
件数:0
select count(*)
from MasterTable
where Code1 = ’A’ and not(Code2 = ’AA’ and Val1 = 1000);
件数:99
数学の論理演算的に考えれば、ここで100件取得できるはずなのに。
でもなぜか99件。不思議!
ちなみに、SQL Server2000の挙動としては以下のようになります。
select count(*)
from MasterTable
where Code1 = ’A’ and (Code2 = ’AA’ and Val1 is null);
件数:1
select count(*)
from MasterTable
where Code1 = ’A’ and not(Code2 = ’AA’ and isnull(Val1,0) = 1000);
件数:100
気分的にはこんな感じ。
プログラマ:「暗黒の儀式とヨーグモスの意思で無限マナ!」
SQL Server:「できません」
プログラマ:「理論的にはできるはずなんだけど……」
SQL Server:「うるさい、俺がそう決めたんだから従え!」
プログラマ:「(´・ω・`)ショボーン」
今日、この条件でselectできないんだけどという問い合わせがありました。
調査結果としてはプログラムバグに分類されるのですが、いまいち納得できない……
とりあえず、防備録として残しておきます。
select count(*)
from MasterTable
where Code1 = ’A’;
件数:100
select count(*)
from MasterTable
where Code1 = ’A’ and (Code2 = ’AA’ and Val1 = 1000);
件数:0
select count(*)
from MasterTable
where Code1 = ’A’ and not(Code2 = ’AA’ and Val1 = 1000);
件数:99
数学の論理演算的に考えれば、ここで100件取得できるはずなのに。
でもなぜか99件。不思議!
ちなみに、SQL Server2000の挙動としては以下のようになります。
select count(*)
from MasterTable
where Code1 = ’A’ and (Code2 = ’AA’ and Val1 is null);
件数:1
select count(*)
from MasterTable
where Code1 = ’A’ and not(Code2 = ’AA’ and isnull(Val1,0) = 1000);
件数:100
気分的にはこんな感じ。
プログラマ:「暗黒の儀式とヨーグモスの意思で無限マナ!」
SQL Server:「できません」
プログラマ:「理論的にはできるはずなんだけど……」
SQL Server:「うるさい、俺がそう決めたんだから従え!」
プログラマ:「(´・ω・`)ショボーン」