select zch from temp_a
结果:
88200940
88200941
88200971
88200640
88200282
88200527
88200528select zch from temp_b
结果:
88200940
88200941
88200971select * from temp_a where zch in (select zch from temp_b )
结果:
88200940
88200941
88200971现在想查找temp_a中zch中不包含在temp_b中zch 的数据
select * from temp_a where zch not in (select zch from temp_b )结果空的,不知道为什么? zch 为varchar(50)的,请高手指教!!!
结果:
88200940
88200941
88200971
88200640
88200282
88200527
88200528select zch from temp_b
结果:
88200940
88200941
88200971select * from temp_a where zch in (select zch from temp_b )
结果:
88200940
88200941
88200971现在想查找temp_a中zch中不包含在temp_b中zch 的数据
select * from temp_a where zch not in (select zch from temp_b )结果空的,不知道为什么? zch 为varchar(50)的,请高手指教!!!
declare @temp_a table(zch varchar(10))
insert into @temp_a values('88200940')
insert into @temp_a values('88200941')
insert into @temp_a values('88200971')
insert into @temp_a values('88200640')
insert into @temp_a values('88200282')
insert into @temp_a values('88200527')
insert into @temp_a values('88200528')
insert into @temp_a values(null)
declare @temp_b table(zch varchar(10))
insert into @temp_b values('88200940')
insert into @temp_b values('88200941')
insert into @temp_b values('88200971')
insert into @temp_b values(null)select
*
from
@temp_a
where
zch in(select zch from @temp_b)
/*
zch
----------
88200940
88200941
88200971
*/select
*
from
@temp_a
where
zch not in(select zch from @temp_b)
/*
zch
----------
*/select
t.*
from
@temp_a t
where
not exists(select 1 from @temp_b where isnull(zch,'')=isnull(t.zch,'')) /*
zch
----------
88200640
88200282
88200527
88200528
*/
--