|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Subquery QuestionFROM SampleSourceArchive ssa WHERE SampleSourceKey = @sampleSourceKey AND CMRKey IS NOT NULL -- is this line not needed AND ssa.ContactPhoneNumber > '' AND NOT EXISTS ( SELECT CMRKey, PhoneNumber FROM CMRPhone WHERE CMRKey = ssa.CMRKey -- because of this line? AND PhoneNumber = ssa.ContactphoneNumber ) I think the answer is yes because a NULL in one table should not ever equal a NULL in another table (or columns in the same table for that matter) Correct? -- Peace & happy computing, Mike Labosh, MCSD "When you kill a man, you're a murderer. Kill many, and you're a conqueror. Kill them all and you're a god." -- Dave Mustane Depends on your ansi null settings
try this declare @1 int,@2 int if @1 = @2 select 'yes' else select 'no' play with SET ANSI_NULLS ON/OFF http://sqlservercode.blogspot.com/ Show quote "Mike Labosh" wrote: > SELECT DISTINCT ssa.CMRKey, ssa.ContactphoneNumber > FROM SampleSourceArchive ssa > WHERE SampleSourceKey = @sampleSourceKey > > AND CMRKey IS NOT NULL -- is this line not needed > > AND ssa.ContactPhoneNumber > '' > AND NOT EXISTS ( > SELECT CMRKey, PhoneNumber > FROM CMRPhone > > WHERE CMRKey = ssa.CMRKey -- because of this line? > > AND PhoneNumber = ssa.ContactphoneNumber > ) > > I think the answer is yes because a NULL in one table should not ever equal > a NULL in another table (or columns in the same table for that matter) > Correct? > > -- > Peace & happy computing, > > Mike Labosh, MCSD > > "When you kill a man, you're a murderer. > Kill many, and you're a conqueror. > Kill them all and you're a god." -- Dave Mustane > > > > declare @1 int,@2 int It said 'no' That's perfect. I will go look at ANSI_NULLS in BOL too.> if @1 = @2 > select 'yes' > else > select 'no' -- Peace & happy computing, Mike Labosh, MCSD "When you kill a man, you're a murderer. Kill many, and you're a conquerer. Kill them all and you're a god." -- Dave Mustane Hi Mike,
In my opinion you're in doing so, it will also make this query optimized. -Hari Hi Mike,
In my opinion you're in doing so, it will also make this query optimized. -Hari Sharma No it's not neededand I've never had to use this filter in a join.
Well there may be an issue with ANSI_NULL but I've always left ANSI_NULL to the default value OFF. Run this in QA: select case WHEN NULL = NULL THEN 'TRUE' WHEN NULL <> NULL THEN 'FALSE' ELSE 'UNKNOWN' END Show quote "Mike Labosh" <mlab***@hotmail.com> wrote in message news:OQT4yCFwFHA.3236@TK2MSFTNGP14.phx.gbl... > SELECT DISTINCT ssa.CMRKey, ssa.ContactphoneNumber > FROM SampleSourceArchive ssa > WHERE SampleSourceKey = @sampleSourceKey > > AND CMRKey IS NOT NULL -- is this line not needed > > AND ssa.ContactPhoneNumber > '' > AND NOT EXISTS ( > SELECT CMRKey, PhoneNumber > FROM CMRPhone > > WHERE CMRKey = ssa.CMRKey -- because of this line? > > AND PhoneNumber = ssa.ContactphoneNumber > ) > > I think the answer is yes because a NULL in one table should not ever > equal a NULL in another table (or columns in the same table for that > matter) Correct? > > -- > Peace & happy computing, > > Mike Labosh, MCSD > > "When you kill a man, you're a murderer. > Kill many, and you're a conqueror. > Kill them all and you're a god." -- Dave Mustane > >> I've always left ANSI_NULL to the default value OFF. << Why? Do you spit on other ANSI/ISO Standards, too? This is a bitchto maintain, to port or even to read if you know SQL. Sorry, I meant ON.
Gee, I just got Celkoed. What a way to finish the week. :-( Show quote "--CELKO--" <jcelko***@earthlink.net> wrote in message news:1127498357.401322.153550@f14g2000cwb.googlegroups.com... >>> I've always left ANSI_NULL to the default value OFF. << > > Why? Do you spit on other ANSI/ISO Standards, too? This is a bitch > to maintain, to port or even to read if you know SQL. > >> Why? Do you spit on other ANSI/ISO Standards, too? This is a bitch OK, so I'll step up and spit on them. If I use quirky Microsoft-only >> to maintain, to port or even to read if you know SQL. > Sorry, I meant ON. > Gee, I just got Celkoed. > What a way to finish the week. :-( techniques, I make it too prohibitive for them to take away my SQL Server and make me learn Oracle or PostGres or MySql or DB2... INSERT INTO Celko VALUES ('Evil Trolling Grin') -- Peace & happy computing, Mike Labosh, MCSD "When you kill a man, you're a murderer. Kill many, and you're a conquerer. Kill them all and you're a god." -- Dave Mustane On Fri, 23 Sep 2005 11:09:02 -0400, Mike Labosh wrote:
Show quote > SELECT DISTINCT ssa.CMRKey, ssa.ContactphoneNumber Hi Mike,> FROM SampleSourceArchive ssa > WHERE SampleSourceKey = @sampleSourceKey > > AND CMRKey IS NOT NULL -- is this line not needed > > AND ssa.ContactPhoneNumber > '' > AND NOT EXISTS ( > SELECT CMRKey, PhoneNumber > FROM CMRPhone > > WHERE CMRKey = ssa.CMRKey -- because of this line? > > AND PhoneNumber = ssa.ContactphoneNumber > ) > >I think the answer is yes because a NULL in one table should not ever equal >a NULL in another table (or columns in the same table for that matter) >Correct? Assuming proper ANSI NULL settings, you could remove the line. But I'd leave it in all the same, for two reasons: 1. Makes the query easier to understand for the readers; 2. Gives the optimizer an extra possibility to save the engine some work, either by checking the NULL condition before performing the subquery, or maybe even by doing an index scan on an index that holds CMRKey. Best, Hugo -- (Remove _NO_ and _SPAM_ to get my e-mail address) |
|||||||||||||||||||||||