?
Solved

Not Equals in MS Access Query

Posted on 2012-04-03
8
Medium Priority
?
482 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
7 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
Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

 
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 2000 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

Granular recovery for Microsoft Exchange

With Veeam Explorer for Microsoft Exchange you can choose the Exchange Servers and restore points you’re interested in, and Veeam Explorer will present the contents of those mailbox stores for browsing, searching and exporting.

Question has a verified solution.

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

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …

840 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