Solved

Not Equals in MS Access Query

Posted on 2012-04-03
8
477 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
  • 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone 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

If you find yourself in this situation “I have used SELECT DISTINCT but I’m getting duplicates” then I'm sorry to say you are using the wrong SQL technique as it only does one thing which is: produces whole rows that are unique. If the results you a…
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.​
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

830 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