Article View: bit.databases.mssql-l
Article #233Re: NULL versus IN (NULL) versus IS NULL
From: Grzegorz Rymarz
Date: Mon, 06 Sep 1999 00:00
Date: Mon, 06 Sep 1999 00:00
85 lines
2691 bytes
2691 bytes
Hi Dan, behaviour of expressions containing nulls depends on current value of ANSI_NULLS session setting. If it is enabled nulls behave in the way you have noticed (SQL-92 conformance!!). After switching it off, your queries will start to work according to your expectations... Regards, Grzegorz Rymarz Dan G wrote: > Hello all, > > Take a moment and read test the below puzzle (could be a good lesson > for > some of us). > Compare the results/performance (and query plans) and respond to the > questions: > Running on SQL 7 (SP1). > > -- case A) <> NULL examples. > > select > count (*) > from > pos > where > cntc_name<>NULL > > select > count (*) > from > pos > where > cntc_name NOT IN (NULL) > > select > count (*) > from > pos > where > cntc_name IS NOT NULL > > Questions: > A) why the execution plans are the same (same predicate) but the > results are > different (BTW last one is the correct one !). > MS SQL 7 shouldn't allow the first two if they give wrong results > ;-(. > > -- B) = NULL > > select > count (*) > from > pos > where > cntc_name=NULL > > select > count (*) > from > pos > where > cntc_name IN (NULL) > > select > count (*) > from > pos > where > cntc_name IS NULL > > Questions: > B) Same question as above + why the filtering is removed from the > execution > plan ?. > > All the best, > > Dan.
Technical Details
Message-ID:
<37D39029.3AD5DA9@hector.com.pl>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7qvuii$o43$1@pollux.ip-plus.net>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10f695,d81f9450cc844161 X-Google-Attributes: gid10f695,public X-Google-Thread: f6611,d81f9450cc844161 X-Google-Attributes: gidf6611,public X-Google-Thread: 107d2f,d81f9450cc844161 X-Google-Attributes: gid107d2f,public X-Google-Thread: 104de1,d81f9450cc844161 X-Google-Attributes: gid104de1,public X-Google-Thread: 109c00,d81f9450cc844161 X-Google-Attributes: gid109c00,public X-Google-Thread: 11301e,d81f9450cc844161 X-Google-Attributes: gid11301e,public From: Grzegorz Rymarz <grzes_r@hector.com.pl> Subject: Re: NULL versus IN (NULL) versus IS NULL Date: 1999/09/06 Message-ID: <37D39029.3AD5DA9@hector.com.pl> X-Deja-AN: 521614509 Content-Transfer-Encoding: 7bit References: <7qvuii$o43$1@pollux.ip-plus.net> X-Trace: news.tpnet.pl 936611851 195.205.152.10 (Mon, 06 Sep 1999 11:57:31 MET DST) Organization: HECTOR S.A. X-Priority: 3 (Normal) Content-Type: text/plain; charset=us-ascii MIME-Version: 1.0 NNTP-Posting-Date: Mon, 06 Sep 1999 11:57:31 MET DST Newsgroups: bit.databases.mssql-l,comp.databases.ms-sqlserver,microsoft.public.sqlserver,microsoft.public.sqlserver.programming,microsoft.public.sqlserver.server,microsoft.public.sqlserver.workshop X-Complaints-To: abuse@tpsa.pl