Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Logic for WHERE clause 1

Status
Not open for further replies.

sxschech

Technical User
Jul 11, 2002
1,034
US
Been having a bit of trouble writing the WHERE clause logic.

In english:
Want to see all people who are not in the deceased list or in the exclusion list regardless of whether they have graduated or not, however if they are deceased or in the exclusion list and have graduated, they should be included/displayed in the query's output.

The statement below seems to be excluding the deceased that have not graduated, but are including people in the exclusion list who have not graduated.

If not deceased want them
If deceased but graduated want them
If not in the exclusion list want them
If in the exclusion list but graduated want them

Code:
SELECT *
FROM (qryFATT 
LEFT JOIN sqlDeceased ON qryFATT.COHORT_PIDM = sqlDeceased.SPBPERS_PIDM) 
LEFT JOIN sqlExclusionReason ON qryFATT.COHORT_PIDM = val(sqlExclusionReason.PERSON_UID) 
WHERE sqlDeceased.SPBPERS_DEAD_IND Is Null 
        OR (sqlDeceased.SPBPERS_DEAD_IND = "Y" and graduated = 1)
        OR sqlExclusionReason.REGISTRATION_REASON is null 
        OR (sqlExclusionReason.REGISTRATION_REASON is not null and graduated = 1);
 
What about this ?
WHERE (sqlDeceased.SPBPERS_DEAD_IND Is Null
AND sqlExclusionReason.REGISTRATION_REASON Is Null)
OR graduated = 1


Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV so far seems to be working. I'll see how it goes with more data next week. Looks a lot simpler than what I came up with too.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top