添加一些详细信息..
简而言之null是不确定的,但也有其产生一些不同的结果
select 1+null--null
select 'A'+null--null
select 1+isnull(null,0)
select 'A'+isnull(null,'n')--null
---some info on nulls
create table #test1
(
id int,
name char(5)
)
create table #test2
(
id int
)
insert into #test2
select 2
union all
select null
insert into #test1
select 1,'a'
union all
select null,'b'
union all
select 3,null
--getting data for all non null fields
select
* from #test1 where id is not null
select * from #test1 where id is null
---all aggregate functions exclude nulls
select sum(id),max(name)
from #test1
---but group by keeps nulls in seperate group
select
sum(id),name
from #test1
group by name
---while comparing or joining against other fields --use is null,since we dont know it may be potentiallly null
select id from #test1 t1 where exists(select 1 from #test2 t2 where t1.id=t2.id)--gives correct results
select id from #test1 t1 where not exists(select 1 from #test2 t2 where t1.id=t2.id)--gives correct results
select id from #test1 t1 where id in (select id from #test2)--gives correct results
select id from #test1 t1 where id not in (select id from #test2)--not gives correct results
检查空的操作'是null',不能以' =' –