(不等于)不适用于简单的访问查询( (not equal) is not working in a simple access query)

编程入门 行业动态 更新时间:2024-10-28 20:24:21
<>(不等于)不适用于简单的访问查询(<> (not equal) is not working in a simple access query)

我有以下查询,我想将所有活动员工的CardStatus <>“丢失卡”放在哪里。

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"));

如果我将<>“丢失的卡”替换为“丢失的卡”

如果我将<>“Lost Card”替换为null,它会起作用(这会给出我期待的结果)

如果我将<>“丢失的卡片”替换为不为null,它将起作用。

无论出于何种原因,它不喜欢“<>”。 是的我知道我可以使用“is null”方案来获得相同的结果,我很好奇为什么<>不起作用。 如果重要的话查询从链接的ODBC连接拉到sql server。

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.

最满意答案

将Null与任何内容进行比较将只返回Null:

?Null<>"Lost Card" Null ?Null="Lost Card" Null

您需要在条件中明确检查Null:

WHERE (CardStatus <> "Lost Card" Or CardStatus Is Null)

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)

更多推荐

本文发布于:2023-07-19 21:50:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1187591.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:不等于   不适用于   简单   equal   query

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!