Solved

Why won't the Access query recognize multiple "Not" statements?

Posted on 2009-07-14
6
522 Views
Last Modified: 2012-05-07
Query does not exclude any records unless I remove one of the Not statements.
Here is Code:
 
SELECT tblRecords.LivID, tblRecords.Sold, tblRecords.TagNo
FROM tblRecords
WHERE (((tblRecords.Sold)=False) AND (Not (tblRecords.TagNo)="0000-0001")) OR ((Not (tblRecords.TagNo)="0000-0003"));

Open in new window

0
Comment
Question by:trbaze
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 92

Expert Comment

by:Patrick Matthews
ID: 24855595
WHERE tblRecords.Sold = False AND Not tblRecords.TagNo = "0000-0001" AND Not tblRecords.TagNo = "0000-0003"


although I prefer:

WHERE tblRecords.Sold = False AND tblRecords.TagNo <> "0000-0001" AND tblRecords.TagNo <> "0000-0003"
0
 
LVL 92

Accepted Solution

by:
Patrick Matthews earned 500 total points
ID: 24855607
If my previous suggestion did not work, then state what the WHERE criteria should be *using sentences*.
0
 
LVL 3

Author Closing Comment

by:trbaze
ID: 31603553
Your suggestion worked.  Thank you very much!  Why wouldn't the "OR" work?
0
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
LVL 3

Expert Comment

by:dinomix
ID: 24855652
Not is a unary operator which reverses a boolean expression. The Not in your WHERE clause is being applied to the tblRecords.TagNo instead of the expression tblRecords.TagNo="0000-0001"

Try this:
WHERE tblRecords.Sold=False AND (Not (tblRecords.TagNo="0000-0001") OR Not (tblRecords.TagNo="0000-0003"));
 
0
 
LVL 20

Expert Comment

by:GrahamMandeno
ID: 24855664
Hi trbaze

If we make the WHERE clause easier to read by removing some brackets, we get:

WHERE ( (tblRecords.Sold=False) AND (Not tblRecords.TagNo="0000-0001") )
OR (Not tblRecords.TagNo="0000-0003")

This will return all records, because TagNo cannot be BOTH "0000-0001" AND "0000-0003".

I think what you really mean is:

WHERE (tblRecords.Sold=False)
AND (tblRecords.TagNo<>"0000-0001")
AND (tblRecords.TagNo<>"0000-0003")
--
Graham Mandeno - Access MVP
0
 
LVL 3

Author Comment

by:trbaze
ID: 24855678
Ok.  I understand.  Thanks again for your help.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question