Query to exclude criteria assistance

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Query to exclude criteria assistance

Post by Michael Abrams »

I have tried many variations on this query, but cannot obtain the desired result.
The following gives me what I originally wanted - all records matching the criteria.

Code: Select all

SELECT ISSUES.RECORDNUM, ISSUES.MEDICAL_GROUP, ISSUES.HMO, ISSUES.SPECIFIC_ISSUE, ISSUES.MEMBER_LAST_NAME, ISSUES.MEMBER_FIRST_NAME, ISSUES.DOB, ISSUES.MEMBER_IDNUM, ISSUES.MEMBER_CODE, ISSUES.MRN, ISSUES.OPENING_NOTES, ISSUES.HMO_NOTIFIED1
FROM ISSUES
WHERE (((ISSUES.DATE_ISSUE_OPENED)<#2/11/2010#))
GROUP BY ISSUES.RECORDNUM, ISSUES.MEDICAL_GROUP, ISSUES.HMO, ISSUES.SPECIFIC_ISSUE, ISSUES.MEMBER_LAST_NAME, ISSUES.MEMBER_FIRST_NAME, ISSUES.DOB, ISSUES.MEMBER_IDNUM, ISSUES.MEMBER_CODE, ISSUES.MRN, ISSUES.OPENING_NOTES, ISSUES.HMO_NOTIFIED1, ISSUES.DATE_RESOLVED
HAVING (((ISSUES.DATE_RESOLVED) Is Null))
ORDER BY ISSUES.MEDICAL_GROUP, ISSUES.HMO;
What I would like it to do, is exclude records where
HMO = AE
and
Specific_Issue = Closed Practice

Thank you very much for your help.

Michael Abrams

User avatar
Wendell
4StarLounger
Posts: 482
Joined: 24 Jan 2010, 15:02
Location: Colorado, USA

Re: Query to exclude criteria assistance

Post by Wendell »

Try this change to the HAVING and ORDER BY lines:

Code: Select all

HAVING ISSUES.DATE_RESOLVED Is Null AND ISSUES.HMO = "AE" AND ISSUES.SPECIFIC_ISSUE = "Closed Practice"
ORDER BY ISSUES.MEDICAL_GROUP;
Note that I've taken the parentheses out to make it a bit more readable - Access will put them back in if you switch to the query grid view. Also note that there is no point in sorting on the HMO field since you have restricted it in the HAVING clause.
Wendell
You can't see the view if you don't climb the mountain!

User avatar
HansV
Administrator
Posts: 78402
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Query to exclude criteria assistance

Post by HansV »

If you want to exclude records with ISSUES.HMO = "AE" AND ISSUES.SPECIFIC_ISSUE = "Closed Practice", change Wendell's suggestion to

HAVING ISSUES.DATE_RESOLVED Is Null AND Not (ISSUES.HMO = "AE" AND ISSUES.SPECIFIC_ISSUE = "Closed Practice")
ORDER BY ISSUES.MEDICAL_GROUP;
Best wishes,
Hans

User avatar
Wendell
4StarLounger
Posts: 482
Joined: 24 Jan 2010, 15:02
Location: Colorado, USA

Re: Query to exclude criteria assistance

Post by Wendell »

Sorry that's what I get for creating air-code in a hurry. I spaced the fact that you wanted to exclude them. And you want to keep the ORDER BY field ISSUES.HMO in that case.
Wendell
You can't see the view if you don't climb the mountain!

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Re: Query to exclude criteria assistance

Post by Michael Abrams »

Hi Guys,

Of course it works perfectly, and no sooner than I showed it to my boss, I was asked to add one more exclusion.
I will show you what I tried, but it doesn't produce the correct results. There is a third "and":
HMO = AE
and
Specific_Issue = Closed Practice
and
HMO_Notified1 is not null

I have tried:

HAVING ISSUES.DATE_RESOLVED Is Null AND Not (ISSUES.HMO = "AE" AND ISSUES.SPECIFIC_ISSUE = "Closed Practice") And Is Null ([HMO_Notified1])

HAVING ISSUES.DATE_RESOLVED Is Null AND Not (ISSUES.HMO = "AE" AND ISSUES.SPECIFIC_ISSUE = "Closed Practice") And ([HMO_Notified1]) = " "

I am sorry that I didn't include this in the OP.

Thanks again.

Michael

User avatar
HansV
Administrator
Posts: 78402
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Query to exclude criteria assistance

Post by HansV »

Try

HAVING ISSUES.DATE_RESOLVED Is Null AND Not (ISSUES.HMO = "AE" AND ISSUES.SPECIFIC_ISSUE = "Closed Practice" AND ISSUES.HMO_Notified1 Is Not Null)

Note that the condition HMO_Notified1 is not null is within the parentheses after Not.
Best wishes,
Hans

User avatar
Michael Abrams
4StarLounger
Posts: 573
Joined: 10 Feb 2010, 17:32

Re: Query to exclude criteria assistance

Post by Michael Abrams »

HansV wrote:Try

HAVING ISSUES.DATE_RESOLVED Is Null AND Not (ISSUES.HMO = "AE" AND ISSUES.SPECIFIC_ISSUE = "Closed Practice" AND ISSUES.HMO_Notified1 Is Not Null)

Note that the condition HMO_Notified1 is not null is within the parentheses after Not.
Works great ! Thank you very much.

Michael