select a.f1,a.f2,b.f1,b.f2 from a left join b on b.f1 = a.f1 where isnull(b.f2,'') <> 'Bad'你要的结果应该是下面的吧! f1 f2 f1 f2 ---------- ---------- ---------- ---------- a 1 a Good c 1 NULL NULL
select * from a left join b on b.f1 = a.f1 where isnull(b.f2,'') <> 'Bad'
select * from a left join b on b.f1 = a.f1 AND isnull(b.f2,'') <> 'Bad'
奇怪了,难道 NULL = 'Bad' ttf1 f2 f3 f4 ---------- ---------- ---------- ---------- a 1 a Good b 1 b Bad c 1 NULL NULL
select * from tt where f4 <> 'Bad' --第三行的f4为NULL也应该不等Bad才对呀
select * from a left join b on b.f1 = a.f1 where b.f2<>'Bad' or b.f2 is null
TO: 楼主: “f1 f2 f3 f4 ---------- ---------- ---------- ---------- a 1 a Good b 1 b Bad c 1 NULL NULL
select * from tt where f4 <> 'Bad' --第三行的f4为NULL也应该不等Bad才对呀”解析: 如果 ANSI_NULLS 选项设为关,则空值之间的比较(如 NULL = NULL)等于 TRUE。空值与任何其它数据类型之间的比较等于 FALSE。 -->所以第三行比较时等于false,故没返回
from a left join b on b.f1 = a.f1
where isnull(b.f2,'') <> 'Bad'你要的结果应该是下面的吧!
f1 f2 f1 f2
---------- ---------- ---------- ----------
a 1 a Good
c 1 NULL NULL
from a left join b on b.f1 = a.f1
where isnull(b.f2,'') <> 'Bad'
from a left join b on b.f1 = a.f1 AND isnull(b.f2,'') <> 'Bad'
ttf1 f2 f3 f4
---------- ---------- ---------- ----------
a 1 a Good
b 1 b Bad
c 1 NULL NULL
select * from tt where f4 <> 'Bad' --第三行的f4为NULL也应该不等Bad才对呀
where b.f2<>'Bad' or b.f2 is null
“f1 f2 f3 f4
---------- ---------- ---------- ----------
a 1 a Good
b 1 b Bad
c 1 NULL NULL
select * from tt where f4 <> 'Bad' --第三行的f4为NULL也应该不等Bad才对呀”解析:
如果 ANSI_NULLS 选项设为关,则空值之间的比较(如 NULL = NULL)等于 TRUE。空值与任何其它数据类型之间的比较等于 FALSE。
-->所以第三行比较时等于false,故没返回