compare not and <>

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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.
 
Ken Snell said:
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?
 
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.
 
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.
 
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.


--

Ken Snell
<MS ACCESS MVP>

neeraj said:
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.





Chris M said:
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?
 
Chris M said:
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.


My thinking was this:
Not True

vs.
<> True
 
Back
Top