Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

<> (not equal) is not working in a simple access query

Tags:

ms-access

I have the following query where I want to pull all active employees where their CardStatus <> "Lost Card".

SELECT
    dbo_Employee.Status, 
    dbo_EmpBadgeNumbers.EmployeeID_FK, 
    dbo_EmpBadgeNumbers.CardID, 
    dbo_EmpBadgeNumbers.CardStatus 
FROM dbo_Employee INNER JOIN dbo_EmpBadgeNumbers 
        ON dbo_Employee.EmployeeID = dbo_EmpBadgeNumbers.EmployeeID_FK 
WHERE (((dbo_Employee.Status) = "Active") 
    AND ((dbo_EmpBadgeNumbers.CardStatus) <> "Lost Card")); 

If I replace the <> "Lost Card" with "Lost Card" it works,

If I replace the <> "Lost Card" with is null it works (which gives the result I'm looking for)

If I replace the <> "Lost Card" with is not null it works.

For whatever reason it doesn't like the "<>". Yes I know I can just use the "is null" scenario to get the same result, I'm curious as to why the <> is not working. If it matters the query is pulling from a linked ODBC connection to sql server.

like image 853
Ben Avatar asked Oct 28 '25 04:10

Ben


2 Answers

Comparing Null to anything will simply return Null:

?Null<>"Lost Card"
Null

?Null="Lost Card"
Null

You need to do an explicit check for Null in your criteria:

WHERE (CardStatus <> "Lost Card" Or CardStatus Is Null)
like image 61
mwolfe02 Avatar answered Oct 30 '25 18:10

mwolfe02


<> never does work with Null.

Incorrect: WHERE CardStatus <> Null
Correct: WHERE CardStatus Is Not Null

like image 42
HK1 Avatar answered Oct 30 '25 17:10

HK1



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!