Nz() 在 MS Access 中不起作用

发布于 2024-11-19 13:57:37 字数 743 浏览 3 评论 0原文

我有一个交叉表查询,它将 Patient_ID 计算为值。

Total = Nz(Count(Research.Patient_ID))+0

我也尝试过:

Total = Nz(Count(Research.Patient_ID)

和...

Total = Nz(Count(Research.Patient_ID, 0)

等。 Nz() 仅在至少一个值不为空时才有效。然而,如果它们全部为空,我就什么也看不到,而不是全是 0。

这是有问题的,因为我将这些查询用作子查询。主查询从该查询(以及其他类似的查询)中获取值并将它们加在一起。不幸的是,如果子查询之一完全为空,那么无论是否应该为空,总和实际上都会为空。

例如:

subquery1: Nz(Count(Research.Patient_ID))+0

subquery2: Nz(Count(Research.All_ID))+0

mainquery: subquery1 + subquery2


if subquery1 = 4, and subquery2 = Null...

mainquery = subquery1 + subquery2
mainquery = Null

当真的...

mainquery = 4

请帮忙。

I have a cross tab query that is counting Patient_ID's as the value.

Total = Nz(Count(Research.Patient_ID))+0

I have also tried:

Total = Nz(Count(Research.Patient_ID)

and....

Total = Nz(Count(Research.Patient_ID, 0)

etc. Nz() only works if at least one value is not null. However, if all of them are null, instead of seeing all 0's, I see nothing.

This is problematic because I am using these queries as subqueries. The main query takes the values from this one (and others like it) and adds them together. Unfortunately, if one of the subqueries is entirely null, then the sum actually turns up null, regardless of whether or not should be.

For example:

subquery1: Nz(Count(Research.Patient_ID))+0

subquery2: Nz(Count(Research.All_ID))+0

mainquery: subquery1 + subquery2


if subquery1 = 4, and subquery2 = Null...

mainquery = subquery1 + subquery2
mainquery = Null

when really...

mainquery = 4

Please help.

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

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

发布评论

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

评论(3

捶死心动 2024-11-26 13:57:37

在此查询中,主查询生成两个子查询中确定的计数之和。这就是你所追求的吗?

SELECT
    Nz(s1.CountOfPatient_ID,0) + Nz(s2.CountOfAll_ID,0)
FROM
    [SELECT Count(Patient_ID) AS CountOfPatient_ID FROM Research]. AS s1,
    [SELECT Count(All_ID) AS CountOfAll_ID FROM Research]. AS s2

In this query, the main query produces the sum of counts determined in two subqueries. Is this what you're after?

SELECT
    Nz(s1.CountOfPatient_ID,0) + Nz(s2.CountOfAll_ID,0)
FROM
    [SELECT Count(Patient_ID) AS CountOfPatient_ID FROM Research]. AS s1,
    [SELECT Count(All_ID) AS CountOfAll_ID FROM Research]. AS s2
姜生凉生 2024-11-26 13:57:37

nz(null, null)+0 将始终为 null,因为 null + everythingnull

如果nz()可以返回null,则只需应用另一个nz()来处理它;

SELECT ... nz(nz([value1], [value2]), 0)

nz(null, null)+0 will always be null as null + anything is null.

If nz() can return null, just apply another nz() to handle it;

SELECT ... nz(nz([value1], [value2]), 0)
不念旧人 2024-11-26 13:57:37

您可能应该更详细地发布主查询的确切部分,其中两个计数相加。

到目前为止,我只能猜测您需要将 NZ() 添加到主查询表达式中,例如(使用伪代码)

mainquery = NZ(subquery1, 0) + NZ(subquery2, 0)

You should probably be more elaborate and post the exact part of your main query where the two counts are being added up.

So far I can only guess that you need to add NZ() to the main query expression, something like (using your pseudo-code)

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