Simple Query?

poporacer

Registered User.
Local time
Today, 12:37
Joined
Aug 30, 2007
Messages
136
I have a table (tblLeaveData) with the following fields
PERNR (Long)
LeaveDate (date)
SickType (text)
DrNote (YesNo)

SickType will have the following values:
"S", "SF", "SD", "SFD", "SPre", "SFPre", "FM"

I need a query that will filter out any "SPre" or "SFPre" where the corresponding DrNote is yes. All other SickType need to be included no matter what the value is of DrNote.

I am not sure why I can't figure this out, it seem fairly simple.:banghead:
 
Try something like

Code:
SELECT PERNR, LeaveDate, SickType, DrNote FROM tblLeaveData
    WHERE ( DrNote = False ) OR
        ( ( DrNote = True ) AND ( SickType <> "SPre" ) AND ( SickType <> "SFPre" ) ) ;

The part that was vexing you is a logical equality for the sick types. You wanted to EXCLUDE two values but SELECT requires INCLUSION, so you have to negate the individual selections. De Morgan's Theorem says "NOT ( A OR B ) = (NOT A ) AND ( NOT B)" - so rather than blocking stuff that equals what you DON'T want, tell it to take everything that you DO want by inverting the individual equalities to become inequalities.
 
Awesome, I appreciate your explanation as well, it works perfectly!
 

Users who are viewing this thread

Back
Top Bottom