我正在尝试将2个参数传递给Jasper报告并获取结果。在SQL查询中,我将它们与查询组合如下。

SELECT
ROUND(SUM(case when Updated_Date BETWEEN $P{secondYear}+"-03-01" AND $P{secondYear}+"-03-31" then Amount else 0 end),2) AS `March` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{secondYear}+"-02-01" AND $P{secondYear}+"-02-29" then Amount else 0 end),2) AS `February` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{secondYear}+"-01-01" AND $P{secondYear}+"-01-31" then Amount else 0 end),2) AS `January` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}+"-12-01" AND $P{firstYear}+"-12-31" then Amount else 0 end),2) AS `December` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}+"-11-01" AND $P{firstYear}+"-11-31" then Amount else 0 end),2) AS `November` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}+"-10-01" AND $P{firstYear}+"-10-31" then Amount else 0 end),2) AS `October` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}+"-09-01" AND $P{firstYear}+"-09-31" then Amount else 0 end),2) AS `September` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}+"-08-01" AND $P{firstYear}+"-08-31" then Amount else 0 end),2) AS `August` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}+"-07-01" AND $P{firstYear}+"-07-31" then Amount else 0 end),2) AS `July` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}+"-06-01" AND $P{firstYear}+"-06-31" then Amount else 0 end),2) AS `June`,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}+"-05-01" AND $P{firstYear}+"-05-31" then Amount else 0 end),2) AS `May`,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}+"-04-01" AND $P{firstYear}+"-04-31" then Amount else 0 end),2) AS `April`
FROM VAT


但是,在我的Jasper报告中,我一直得到的所有月份的增值税均为0。我做错了什么?

最佳答案

我找到了答案。在jasper报表中,如果要在SQL查询中像parameters那样组合String,则不应使用+符号。因此,正确的代码如下。

SELECT
ROUND(SUM(case when Updated_Date BETWEEN $P{secondYear}"-03-01" AND $P{secondYear}"-03-31" then Amount else 0 end),2) AS `March` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{secondYear}"-02-01" AND $P{secondYear}"-02-29" then Amount else 0 end),2) AS `February` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{secondYear}"-01-01" AND $P{secondYear}"-01-31" then Amount else 0 end),2) AS `January` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}"-12-01" AND $P{firstYear}"-12-31" then Amount else 0 end),2) AS `December` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}"-11-01" AND $P{firstYear}"-11-31" then Amount else 0 end),2) AS `November` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}"-10-01" AND $P{firstYear}"-10-31" then Amount else 0 end),2) AS `October` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}"-09-01" AND $P{firstYear}"-09-31" then Amount else 0 end),2) AS `September` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}"-08-01" AND $P{firstYear}"-08-31" then Amount else 0 end),2) AS `August` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}"-07-01" AND $P{firstYear}"-07-31" then Amount else 0 end),2) AS `July` ,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}"-06-01" AND $P{firstYear}"-06-31" then Amount else 0 end),2) AS `June`,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}"-05-01" AND $P{firstYear}"-05-31" then Amount else 0 end),2) AS `May`,
ROUND(SUM(case when Updated_Date BETWEEN $P{firstYear}"-04-01" AND $P{firstYear}"-04-31" then Amount else 0 end),2) AS `April`
FROM VAT


如果您使用Jaspersoft Studio,它将在查询编辑器中显示为错误。但是,它没有问题。

关于java - 将参数传递给Jasper Reports的问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/27518666/

10-10 21:39