繁体   English   中英

DB2和Jasper Reports中的COALESCE问题

[英]Issue with COALESCE in DB2 and Jasper Reports

我有一个查询,其中我从通过子查询形成的表中取出一列的总和。

行中的东西:

select temp.mySum as MySum from (select sum(myColumn) from mySchema.myTable) temp;

但是,当temp.mySum为null时,我不希望MySum为null。 相反,当temp.mySum为null时,我希望MySum携带字符串'value not available'。

因此我尝试以下面的方式使用coalesce:

select coalesce(temp.mySum, 'value not available') as MySum from (select sum(myColumn) from mySchema.myTable) temp;

但是上面的查询是抛出错误信息:

Message: The data type, length or value of argument "2" of routine "SYSIBM.COALESCE" is incorrect.

此消息是由于合并函数的参数1和2之间的数据类型不兼容,如下面的第一个答案中所述。

但是,我直接在Jasper中使用此查询将值发送到Excel工作表报告:

hashmap.put("myQuery", this.myQuery);
JasperReport jasperReportOne = JasperCompileManager.compileReport(this.reportJRXML);
JasperPrint jasperPrintBranchCd = JasperFillManager.fillReport(jasperReportOne , hashmap, con);
jprintList.add(jasperPrintOne);
JRXlsExporter exporterXLS = new JRXlsExporter();
exporterXLS.setParameter(JRExporterParameter.JASPER_PRINT_LIST, jprintList);
exporterXLS.exportReport();

在excel表中,当值不可用时,我将值变为null。 我想在报告中显示“值不可用”。

怎么能实现这一目标?

谢谢阅读!

合并的论据必须兼容。 如果第一个是数字(如mySum可能是)而第二个是字符串则不是这种情况。

例如,以下PubLib doco有一个表,指示各种类型之间的兼容性,至少对于我使用的DB2(大型机一个) - 毫无疑问,对于iSeries和LUW变体也存在类似的限制。

您可以尝试使用coalesce(temp.mySum, 0)类的东西coalesce(temp.mySum, 0)或者将第一个参数转换为类似char()的字符串。 其中任何一个都应该起作用,因为它们使两个参数兼容。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM