If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > PC based Database Applications > Microsoft Access > Query criteria with multiple "Not equal to"

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-27-11, 12:53
Accessguy Accessguy is offline
Registered User
 
Join Date: Feb 2009
Posts: 30
Query criteria with multiple "Not equal to"

I have a situation where I have to pull data from a table through a query, but I have to exclude or filter out approximately 100+ different types of Clinic codes. I've included a simplified version of the SQL below, but there would be over 100 of the PTCLINIC codes that I would have to filter out. I know Access has its limits and it seems extremely inefficient for me to type this out and have it process in the criteria. There must be a simple solution, but I can't think of what that would be. Can I put the codes in a table and somehow compare it to that table and ask to exclude? If you ask me to write code, I may be a little lost on where to put that code. Unfortunately this is a text field opposed to numeric, so it makes it difficult for the few places I can select a range, like 039-072, I'll have to type them out individually. I cannot seem to find a solution anywhere I look, so I appreciate your help.

SELECT P.PTCLINIC
FROM P
WHERE (((P.PTCLINIC)<>"002" Or (P.PTCLINIC)<>"006" Or (P.PTCLINIC)<>"171" Or (P.PTCLINIC)<>"181"));
Reply With Quote
  #2 (permalink)  
Old 04-27-11, 13:34
pbaldy pbaldy is offline
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,475
For starters, you'd need to use AND rather than OR. The simpler SQL solution would be an IN() clause, but the best solution is the table you've described. Create/populate that table then use the unmatched query wizard to get the records that are not in that table.
__________________
Paul
Reply With Quote
  #3 (permalink)  
Old 04-27-11, 14:52
Accessguy Accessguy is offline
Registered User
 
Join Date: Feb 2009
Posts: 30
Fantastic, you just saved me a lot of time trying to figure this out and I will use this in the future. Both worked great. Thanks so much, this site is very helpful.
Reply With Quote
  #4 (permalink)  
Old 04-27-11, 14:56
pbaldy pbaldy is offline
Registered User
 
Join Date: May 2005
Location: Nevada, USA
Posts: 2,475
Happy to help!
__________________
Paul
Reply With Quote
Reply

Tags
criteria, multiple

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On