Thread View: borland.public.vdbase.data.sql
4 messages
4 total messages
Started by Mark Berry
Wed, 03 Mar 1999 00:00
Are "<>" and "NOT =" equal?
Author: Mark Berry
Date: Wed, 03 Mar 1999 00:00
Date: Wed, 03 Mar 1999 00:00
33 lines
1751 bytes
1751 bytes
Hi, More unexpected SQL behavior. Here part of a post from another forum I'm working with, news://gmnews.goldminesw.com/Public.GoldMine.Programming . As background, you need to know that ContSupp has one record with AccountNo = "90CF-SYSTEM-REC"; the RecType of that record is blank. Nelson/GM wrote: > Wierdness.. I tried the following: > > SELECT * FROM ContSupp WHERE (Contsupp.AccountNo = '90CF-SYSTEM-REC') and > (RecType <> 'H') > > And no records were returned. I should have seen one record. So then I > tried: > > SELECT * FROM ContSupp WHERE (Contsupp.AccountNo = '90CF-SYSTEM-REC') and > (NOT RecType = 'H') > > And guess what, my one record was returned! Very strange this SQL... After > some reading it turns out that SQL has three logic values, TRUE, FALSE or > NULL. My theory is that for some reason <> returns a NULL condition on an > unpopulated RecType like that used by the '90CF' record. This is probably > due to the fact that <> tests if a value exists (greater than or less than) > where as the NOT test that a value does not exist. Are "<>" and "NOT =" really supposed to give different results? Is Nelson correct that it has something to do with NULL? Thanks, Mark Berry
Re: Are "<>" and "NOT =" equal?
Author: Romain Strieff [TeamB]
Date: Thu, 04 Mar 1999 00:00
Date: Thu, 04 Mar 1999 00:00
16 lines
897 bytes
897 bytes
In article <36DD8F52.A95841B5@nospam.mcbsys.com>, Mark Berry politely paraphrased ... > Are "<>" and "NOT =" really supposed to give different results? Is > Nelson correct that it has something to do with NULL? > > Not true= false // and not NULL Not false=true // and not NULL -- Romain Strieff [TeamB] Please read this newsgroup guide below before posting on the private Inprise newsgroups. http://www.inprise.com/newsgroups/guide.html --
Re: Are "<>" and "NOT =" equal?
Author: Steve Koterski
Date: Thu, 04 Mar 1999 00:00
Date: Thu, 04 Mar 1999 00:00
33 lines
2042 bytes
2042 bytes
On Wed, 03 Mar 1999 11:36:50 -0800, Mark Berry <markb@nospam.mcbsys.com>
wrote:
[...]
>> And guess what, my one record was returned! Very strange this SQL... After
>> some reading it turns out that SQL has three logic values, TRUE, FALSE or
>> NULL. My theory is that for some reason <> returns a NULL condition on an
>> unpopulated RecType like that used by the '90CF' record. This is probably
>> due to the fact that <> tests if a value exists (greater than or less than)
>> where as the NOT test that a value does not exist.
>
>Are "<>" and "NOT =" really supposed to give different results? Is
>Nelson correct that it has something to do with NULL?
That's what I figured the problem was -- before I even got that far down in
the article. Yes, the methods used in SQL (not just local SQL) are
different for NULL values. You cannot use the normal comparison operators
available in local SQL: NOT =, <>, or !=. You have to use the NOT NULL
predicate.
For example:
SELECT *
FROM ContSupp C
WHERE (C.AccountNo = "90CF-SYSTEM-REC") AND
((C.RecType != "H") OR (C.RecType IS NULL))
//////////////////////////////////////////////////////////////////////////
Steve Koterski "My problem lies in reconciling my gross
Technical Publications habits with my net income."
INPRISE Corporation -- Errol Flynn (1909-1959)
http://www.borland.com/delphi
Re: Are "<>" and "NOT =" equal?
Author: Mark Berry
Date: Fri, 05 Mar 1999 00:00
Date: Fri, 05 Mar 1999 00:00
43 lines
1932 bytes
1932 bytes
Steve Koterski wrote: > > On Wed, 03 Mar 1999 11:36:50 -0800, Mark Berry <markb@nospam.mcbsys.com> > wrote: > > > That's what I figured the problem was -- before I even got that far down in > the article. Yes, the methods used in SQL (not just local SQL) are > different for NULL values. You cannot use the normal comparison operators > available in local SQL: NOT =, <>, or !=. You have to use the NOT NULL > predicate. > > For example: > > SELECT * > FROM ContSupp C > WHERE (C.AccountNo = "90CF-SYSTEM-REC") AND > ((C.RecType != "H") OR (C.RecType IS NULL)) Thanks, Steve, but as Nelson said, it seems to work fine with just NOT C.RecType = "H" Let's see if I understand this... The "=" operator will find the "H" row(s), so NOTting it will return all the other rows, including RecType of NULL (which is, I assume, how it sees an empty value in a table, though I didn't think dBASE5 tables supported null values). I have to admit it still isn't clear to me why that gives a different result than C.RecType <> "H" In that row, we're asking "Is NULL <> 'H'?". So the result is either True, or did I read somewhere that any expression with NULL in it returns NULL? If you can recommend a good book where I can find an explanation, by all means... Thanks, Mark Berry
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads