Solved

Not Equals in MS Access Query

Posted on 2012-04-03
8
478 Views
Last Modified: 2012-12-02
From what I've seen this should work however it does not.
not equal ms accessalthough the SQL looks as I'd expect
...
WHERE (((BI.NRS_STATION)<>[NRS_STATION_IGNORE].[NRS_STATION_CODE]) AND...

Open in new window

I'm wanting to 'not include' any of the nursing stations that are present in the nrs_station_ignore table.

Thoughts?
0
Comment
Question by:markloessi
[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
  • 2
  • 2
  • 2
  • +1
8 Comments
 
LVL 77

Expert Comment

by:peter57r
ID: 37804005
You can use :
WHERE (BI.NRS_STATION Not In (Select NRS_STATION_CODE] from [NRS_STATION_IGNORE]))
0
 
LVL 27

Expert Comment

by:tliotta
ID: 37804250
Because there is an "AND" following your 'not equal' condition, that has a good chance of causing the problem. Whenever 'not equal' is combined with an "AND" in a WHERE clause, the entire WHERE clause needs to be known.

It's not always intuitive why it goes wrong, but it's usually easy to spot.

It might even affect the result with "NOT IN()".

Please show the entire clause if the problem continues.

Tom
0
 
LVL 12

Expert Comment

by:danishani
ID: 37804376
I don't see any joins with the tables you have shown in your screenshot.

I don't know if they are part of your SQL (Query) or not, but just want to mentioned it in case they are.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

by:tliotta
ID: 37808777
To clarify, the "AND" isn't necessarily exactly the problem; but it indicates that there is more of the WHERE clause than we can see. It will be the totality of the WHERE clause that will be important when "not equal" is part of it.

RichardRost's suggestion to build the WHERE clause a segment at a time is a very good one. At some point of complexity, you should see that results get off track. That will be the point when the parts of the WHERE clause need explanation.

Tom
0
 
LVL 12

Expert Comment

by:danishani
ID: 37809076
It would be very helpful if you can post the whole SQL statement you have.
0
 
LVL 77

Accepted Solution

by:
peter57r earned 500 total points
ID: 37809921
The <> is wrong.  You must use a Not In() or equivalent.

The <> is wrong because the query is generating multiple records for each NRS-Station value and only one of those records will have a matching NRS-Station_code and so be excluded.  The other NRS-Station records will have all other possible values for NRS_Station_code and so will be selected.
To exclude all records from the result for all values of NRS_Station_code you must use the Not In() or equivalent code.
You don't actually need to include the [NRS_STATION_IGNORE] table in the query at all, so remove it.
0
 
LVL 9

Expert Comment

by:keyu
ID: 37822537
Agreed with peter57r

this is best option

WHERE (BI.NRS_STATION Not In (Select NRS_STATION_CODE] from [NRS_STATION_IGNORE]))
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

738 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