null = null with ansi_nulls off
From: Alex (anonymous_at_discussions.microsoft.com)
Date: 06/09/04
- Next message: Amelia: "Dynamic SQL and IN list - Thanks!"
- Previous message: Joe Horton: "Re: Query Help"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 9 Jun 2004 15:00:03 -0700
I've been trying to compare data in two tables. Because
nulls are expectable I'm using set ansi_nulls off so
that 'value' = null returns false and null = null returns
true. However, this is not the observed behavior. The
following block of code demonstrates:
set ansi_nulls off
--prove that null = null returns true
select case when null = null then 'true' when not (null =
null) then 'false' else 'undefined' end
--create dummy tables
select 1 as a1, null as a2 into #a
select 1 as b1, null as b2 into #b
--count expected 1 to 1 join on null = null
select count(*) from #a inner join #b on a2 = b2
--run same test as before on nulls from two different
tables
select case when a2 = b2 then 'true' when not (a2 = b2)
then 'false' else 'undefined' end
from #a inner join #b on a1 = b1
--cleanup
drop table #a
drop table #b
set ansi_nulls on
The expected results would be [true, 1, true] (or, if
ansi_nulls on, [undefined, 0, undefined]) but instead I
get [true, 0, undefined]. Is this supposed to happen? Is
this my machine or settings? Any help or insight is
appreciated.
Yes I know I can get around this problem and I have, but
this is bothering me.
I'm running SQL Server 2000 SP3a on Win XP Pro SP1
- Next message: Amelia: "Dynamic SQL and IN list - Thanks!"
- Previous message: Joe Horton: "Re: Query Help"
- Messages sorted by: [ date ] [ thread ]