如何强制 BIRT 显示零值?

发布于 2024-08-23 09:20:26 字数 462 浏览 3 评论 0原文

我在BIRT报告中遇到了一个情况。我创建的报告坚持将某些字段显示为空白而不是零。当字段实际上是不返回行的子选择时,就会出现这种情况。

例如,如果选择包括:

0 as p3,

那么 0 就可以正常显示。但是,如果选择有:

(select sum(other_field) from other_table where ...) as p3,

该字段显示为空白。

修改数据以使子选择存在的行会导致显示值,即使它们的结果值为零

所以我认为 BIRT 以某种方式将返回零行的子选择视为 NULL(它也显示为空单元格)而不是零。有谁知道如何强制 BIRT 显示实际的 0 而不是空单元格?

如果有人需要发布特定于 DBMS 的答案,我正在使用 DB2/z v8,尽管基于其他供应商的建议也会受到赞赏。

I have a situation in BIRT reporting. A report I created is insisting on displaying some fields as blank rather than zero. The situation arises when the field is actually a sub-select that returns no rows.

So for example, if the select includes:

0 as p3,

then the 0 is displayed okay. If however, the select has:

(select sum(other_field) from other_table where ...) as p3,

the field is displaying blank.

Modifying the data so that rows exist for the sub-select results in a value being displayed, even if their resultant value is zero.

So I'm thinking that somehow BIRT is treating a sub-select returning zero rows as a NULL (which it also displays as an empty cell) rather than a zero. Does anyone have any idea how to coerce BIRT into displaying an actual 0 rather than an empty cell?

I'm using DB2/z v8 if anyone needs to post a DBMS-specific answer, although even suggestions based on other vendors would be appreciated.

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

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

发布评论

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

评论(3

用心笑 2024-08-30 09:20:26

当列或表达式可能返回 NULL 时,尝试使用 COALESCE 函数强制指定一个值。

COALESCE((select sum(other_field) from other_table where ...), 0) as p3,

Try using the COALESCE function to force a value when a column or expression might return NULL.

COALESCE((select sum(other_field) from other_table where ...), 0) as p3,
凉月流沐 2024-08-30 09:20:26

另一种方法,虽然不那么优雅,但有时​​是必要的(例如,如果您正在执行无法更改的存储过程),那就是使用JavaScript在运行时强制显示“0”。

使用以下表达式进行数据绑定:

if (dataSetRow["your_data_set"] == null)
{
    0
}
else
{
    dataSetRow["your_data_set"]
}

根据数据类型,您可能需要向零添加引号

"0"

以表示字符串,如果没有引号,则将其视为整数。

Another way, although not as elegant but sometimes necessary (e.g. if your are executing a stored procedue that you cannot change), would be to use JavaScript to force the display of "0" at run time.

Use the following expression for your data binding:

if (dataSetRow["your_data_set"] == null)
{
    0
}
else
{
    dataSetRow["your_data_set"]
}

Depending on the data type you might need to add quotes to the zero

"0"

to represent Strings, without quotes it is treated as an Integer.

水染的天色ゝ 2024-08-30 09:20:26

在使用十进制数据时,我能够快速对该字段进行 +0 作为缩短版本。

dataSetRow["your_data_set"]+0

While using decimal data I was able to do a quick +0 to the field as a shortened version.

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