访问查找表

发布于 2024-11-12 22:35:33 字数 318 浏览 3 评论 0原文

我需要在 Access 中创建一个查找表,其中所有缩写都与一个值相关,如果缩写(在主表中)为空,那么我想显示“未知”

我得到了工作值,但我可以似乎没有让空值出现。

我的查找表看起来像这样:

REQUEST     REQUEST_TEXT
------------------------
A           Approve
D           Disapprove
NULL        N/A

但是当我按请求进行计数时,它只显示 A 和 D 的值,尽管我知道其中也有一些空白。

我做错了什么?

i need to create a lookup table in Access, where all the abbreviations are related to a value, and if the abbreviation (in the main table) is null, then i want to show "Unknown"

i got the values working, but i can't seem to get the nulls to show up.

my lookup table looks like this:

REQUEST     REQUEST_TEXT
------------------------
A           Approve
D           Disapprove
NULL        N/A

but when i do a count by request, it only shows me values for A and D, all though i know there are some blanks in there as well.

what am i doing wrong?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

他夏了夏天 2024-11-19 22:35:33

如果您更改 tblLookup,这应该会更容易。

REQUEST     REQUEST_TEXT
------------------------
A           Approve
D           Disapprove
U           Unknown

然后,在 tblMain 中,将 REQUEST 字段更改为必需 = True 和默认值 =“U”。添加新记录时,除非用户将其更改为 A 或 D,否则它们将具有 U 表示 REQUEST。

然后,在 REQUEST 上连接 2 个表的查询应该会得到我认为您想要的结果。

SELECT m.REQUEST, l.REQUEST_TEXT
FROM tblMain AS m
    INNER JOIN tblLookup AS l
    ON l.REQUEST = m.REQUEST;

您还应该在两个表之间创建关系,并选择强制引用完整性的选项,以防止用户为 REQUEST 添加虚假值,例如“X”。

编辑
如果无法更改 tblMain 结构,并且您是在 Access 会话中执行此操作,则可以在 LEFT JOIN 上使用 Nz() 函数。

SELECT m.REQUEST, Nz(l.REQUEST_TEXT, "Unknown")
FROM tblMain AS m
    LEFT JOIN tblLookup AS l
    ON l.REQUEST = m.REQUEST;

如果您从 Access 会话外部(例如从 ASP)执行此操作,则 Nz() 函数将不可用。因此,您可以用 IIf() 表达式替换 Nz()。

SELECT m.REQUEST, IIf(l.REQUEST_TEXT Is Null, "Unknown", l.REQUEST_TEXT)
FROM tblMain AS m
    LEFT JOIN tblLookup AS l
    ON l.REQUEST = m.REQUEST;

Edit2:您不能直接使用 Null 值进行 JOIN。但是,对于我建议 tblLookup 的“Unknown”行,您可以使用包含 Nz 的 JOIN 进行 tblMain.REQUEST

SELECT m.id, m.request, l.request_text
FROM tblMain AS m
    INNER JOIN tblLookup AS l
    ON Nz(m.request,"U") = l.request;

如果您想将 tblLookup REQUEST 保留为 Null for REQUEST_TEXT = Unknown,我想您可以在 JOIN 的两侧使用 Nz表达。然而,加入 Nulls 的整个想法让我感到畏缩。我会修理桌子。

This should be easier if you change tblLookup.

REQUEST     REQUEST_TEXT
------------------------
A           Approve
D           Disapprove
U           Unknown

Then, in tblMain, change the REQUEST field to Required = True and Default Value = "U". When new records are added, they will have U for REQUEST unless the user changes it to A or D.

Then a query which JOINs the 2 tables on REQUEST should get you what I think you want.

SELECT m.REQUEST, l.REQUEST_TEXT
FROM tblMain AS m
    INNER JOIN tblLookup AS l
    ON l.REQUEST = m.REQUEST;

You should also create a relationship between the 2 tables, and select the option to enforce referential integrity in order to prevent the users from adding a spurious value such as "X" for REQUEST.

Edit:
If changing tblMain structure is off the table, and if you're doing this from within an Access session, you can use the Nz() function on a LEFT JOIN.

SELECT m.REQUEST, Nz(l.REQUEST_TEXT, "Unknown")
FROM tblMain AS m
    LEFT JOIN tblLookup AS l
    ON l.REQUEST = m.REQUEST;

If you're doing this from outside an Access session, like from ASP, the Nz() function will not be available. So you can substitute an IIf() expression for Nz().

SELECT m.REQUEST, IIf(l.REQUEST_TEXT Is Null, "Unknown", l.REQUEST_TEXT)
FROM tblMain AS m
    LEFT JOIN tblLookup AS l
    ON l.REQUEST = m.REQUEST;

Edit2: You can't directly JOIN with Null values. However with the "Unknown" row I suggested for tblLookup, you could use a JOIN which includes Nz for tblMain.REQUEST

SELECT m.id, m.request, l.request_text
FROM tblMain AS m
    INNER JOIN tblLookup AS l
    ON Nz(m.request,"U") = l.request;

If you want to leave tblLookup REQUEST as Null for REQUEST_TEXT = Unknown, I suppose you could use Nz on both sides of the JOIN expression. However, this whole idea of joining Nulls makes me cringe. I would fix the tables instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文