views:

64

answers:

2

I am using Ms access 2000,

This query is filtering when I use "=" condition, but it is not filtering when i use "<>". What might be the problem?

SELECT tblRevRelLog_Detail.RevRelTrackingNumber, tblRevRelLog_Detail.PartNumber, tblRevRelLog_Detail.ChangeLevel, tblRevRelLog_Detail.Version, tblRevRelLog_Detail.JobPnType, tblRevRelLog_Detail.EdsName, tblRevRelLog_Detail.FmeaText1, tblRevRelLog_Detail.FmeaText2, tblRevRelLog_Detail.LasdtEvent, tblRevRelLog_Detail.DetailerNamePerPartNumber, tblRevRelLog_Detail.DetailerCompanyPerPartNumber
FROM tblRevRelLog_Detail LEFT JOIN tblEventLog ON tblRevRelLog_Detail.PartNumber = tblEventLog.PartNumber
WHERE (((tblEventLog.EventTypeSelected)<> 'Pn REMOVED from Wrapper'));
A: 

Maybe the column has null values? SQL (and hence, I suppose Access) uses three valued logic. There is true, false, and unknown. and NUll values are assumed unknown. So

WHERE col = 'value'

returns all rows where col is not null and has the value 'value'

WHERE col <> 'value'

returns all rows where col is not null and the value of col is not 'value'

WHERE col is null

returns all rows where col is null.

To return the rows that do not fulfill col = 'value', you will have to use

WHERE col is null OR col <> 'value'
Frank
No, column has values..
Are you sure? The left join may introduce NULLs on the columns of tblEventLog in the result set.
Frank
If there are no values..how can it compare when I use "=" condition
As I put in my answer at the end, using "IS NULL".
Frank
A: 

Why not try:

SELECT td.RevRelTrackingNumber,
       td.PartNumber,
       td.ChangeLevel,
       td.Version,
       td.JobPnType,
       td.EdsName,
       td.FmeaText1,
       td.FmeaText2,
       td.LasdtEvent,
       td.DetailerNamePerPartNumber,
       td.DetailerCompanyPerPartNumber
FROM   tblRevRelLog_Detail td
LEFT JOIN tblEventLog te ON td.PartNumber = te.PartNumber
WHERE NOT(((te.EventTypeSelected) = 'Pn REMOVED from Wrapper'));

Not much of an Access person, but I believe that would acheive what you want.

XstreamINsanity
I do not see any difference in the query, but still i tried and gives the same result..If i delete NOT from the query ...it is filtering the recordsSo, no diff between yours and mine
I wouldn't be surprised if Jet/ACE optimizes it exactly the same, since it is logically equivalent. You can find out by turning on SHOWPLAN (google on "Jet SHOWPLAN" for instructions on turning it on). It's also dangerous as a general recommendation with Jet/ACE because with subqueries, NOT often performs poorly because for some reason it fails to use the indexes on boths sides (which it does in say IN and EXISTS -- it's only the NOT that causes the problem).
David-W-Fenton
Access doesn't like "!=" does it?
XstreamINsanity
Also, you can do AND instead of WHERE. LEFT OUTER JOIN tblEventLog te ON td.PartNumber = te.PartNumber AND ... I put ... because that would be the NOT or the <> or whichever you/we get to work.
XstreamINsanity
FROM tblRevRelLog_Detail LEFT JOIN tblEventLog ON (tblRevRelLog_Detail.PartNumber = tblEventLog.PartNumber) AND (tblEventLog.EventTypeSelected<> 'Pn REMOVED from Wrapper');This is what you are saying right? No....that is not the right syntax...
LEFT JOIN tblEventLog te ON td.PartNumber = te.PartNumber AND te.EventTypeSelected <> 'Pn REMOVED from wrapper'. That is the same as using it in the WHERE clause, at least that what I'm aware of. Even uses less processing I think. Could be wrong though.
XstreamINsanity
Jet/ACE optimizes equivalent implicit and explicit joins identically, so, no, there's unlikely to be any benefit to converting the WHERE to non-equi-join.
David-W-Fenton
It occurred to me after I posted that maybe the NOT version was not equivalent, but just checking in Access/Jet, I find that it returns the same result set as <>. To get the set-based version of this, you'd have to use a subquery, and that would likely be less efficient than adding the criterion to return Nulls.
David-W-Fenton