Solved

Not Equals in MS Access Query

Posted on 2012-04-03
8
475 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 
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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

PL/SQL can be a very powerful tool for working directly with database tables. Being able to loop will allow you to perform more complex operations, but can be a little tricky to write correctly. This article will provide examples of basic loops alon…
Preparing an email is something we should all take special care with – especially when the email is for somebody you may not know very well. The pressures of everyday working life stacked with a hectic office environment can make this a real challen…
Familiarize people with the process of utilizing SQL Server stored procedures 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 Micr…
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.

803 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