Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Queries / November 2005

Tip: Looking for answers? Try searching our database.

compare not and <>

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
neeraj - 03 Nov 2005 04:23 GMT
Can there ever be a difference between results produced by <> and those
produced by not whenever they can be used in the same place in a query
Ken Snell [MVP] - 03 Nov 2005 05:09 GMT
Sure -- depending upon the data type of the values. Not is a negation
operator, meaning it turns True into False, or False into True. The not
equals operator (<>) is a comparison operator, and does not change a value
at all.

Signature

       Ken Snell
<MS ACCESS MVP>

> Can there ever be a difference between results produced by <> and those
> produced by not whenever they can be used in the same place in a query
Chris M - 03 Nov 2005 10:47 GMT
>> Can there ever be a difference between results produced by <> and those
>> produced by not whenever they can be used in the same place in a query

> Sure -- depending upon the data type of the values. Not is a negation
> operator, meaning it turns True into False, or False into True. The not
> equals operator (<>) is a comparison operator, and does not change a value
> at all.

Can't really think how <> and NOT are interchangable, unless he is asking if
'NOT(a=b) is the same as (a<>b)?
Those 2 are logically equivilent and will always produce the same result.

Neeraj: Are you asking this due to a specific problem you have, or just
general interest?
neeraj - 03 Nov 2005 17:36 GMT
I am not asking due to a specific problem but out of general interest. I have
been using both not and <> in the criteria row of the design grid of my
queries interchangeably as it has always yielded same results. I was curious
exactly because of this reason: if they have been yielding same results, was
that just because of the specific data sets that I have dealt with or could I
ever encounter a case where results would be different with <> and "not" and
my results would be erroneous because I chose the wrong one randomly.
Ken has written that the difference will depend upon the data type of
values. How does data type affect the difference in results of not and <> ?
To take a simple example, say there is a table Months with 2 fields: Month
and Month Number with these values:
Month Number Month
1                     January
2                     February
....
12                   December
I have the following 2 queries one with <> and the other with "not"
Query1:
SELECT Months.Month, Months.[Month Number]
FROM Months
WHERE (((Months.[Month Number])<>"1"));

Query2:
SELECT Months.Month, Months.[Month Number]
FROM Months
WHERE ((Not (Months.[Month Number])="1"));

Both queries produce the same results that is all months except January. I
have always found the results to be the same using <> and not in the above
way.
Can the results ever be different using <> and not in this way and if yes,
what would that case be? Thanks.

> >> Can there ever be a difference between results produced by <> and those
> >> produced by not whenever they can be used in the same place in a query
[quoted text clipped - 10 lines]
> Neeraj: Are you asking this due to a specific problem you have, or just
> general interest?
Ken Snell [MVP] - 03 Nov 2005 23:07 GMT
Ahhh... the situation you show is one where Not will work the way you want.
That is because this statement:
       Months.[Month Number]<>"1"

produces a True or False result. The field either equals "1" or it doesn't.
Putting Not in front of it changes it from True to False or vice versa.

Signature

       Ken Snell
<MS ACCESS MVP>

>I am not asking due to a specific problem but out of general interest. I
>have
[quoted text clipped - 52 lines]
>> Neeraj: Are you asking this due to a specific problem you have, or just
>> general interest?
Ken Snell [MVP] - 04 Nov 2005 01:55 GMT
>>> Can there ever be a difference between results produced by <> and those
>>> produced by not whenever they can be used in the same place in a query
[quoted text clipped - 7 lines]
> if 'NOT(a=b) is the same as (a<>b)?
> Those 2 are logically equivilent and will always produce the same result.

My thinking was this:
       Not True

vs.
       <> True

Signature

       Ken Snell
<MS ACCESS MVP>

Van T. Dinh - 03 Nov 2005 15:30 GMT
Not sure of your question here: they are 2 different types of operators: NOT
is a *unary* operator (meaning it operates on ONE operand) while <> is a
*binary* operator (requiring TWO operands).

You can't really say that they are equivalent since they are different types
of operator operating in different ways.

Signature

HTH
Van T. Dinh
MVP (Access)

> Can there ever be a difference between results produced by <> and those
> produced by not whenever they can be used in the same place in a query
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.