JasperReports parameter value required to display all

I tried this problem for a while, and hope you can help me.

I have a report made in iReport, and I would like the report to be completed even if some parameters are equal to zero.

That's what i

SELECT
    evento."titulo" AS evento_titulo,
    evento."data_inicio_realizacao" AS evento_data_inicio_realizacao,
    evento."data_fim_realizacao" AS evento_data_fim_realizacao,
    evento."id" AS evento_id
FROM
    "public"."evento" evento
WHERE
    evento."id" = $P{eventoid} OR
    evento."data_inicio_realizacao" BETWEEN $P{data1} AND $P{data2}

I would like the WHERE clause to be optional, that is, if I leave these parameters null (or 0-valued in the case of id), I want to get all the values ​​instead of a clean report.

Is it possible? I found that some people make $ P {WHERE_CLAUSE} and pass the whole where clause as its value, but this did not work for me.

+3
source share
3 answers

, , , WHERE $P {}.

WHERE :

$P!{whereClause}

$P {eventoid}, $P {data1} $P {data2}.

Spring MVC Controller, POST , String, whereClause, "WHERE 1 = 1" ( true if ):

String whereClause = "WHERE 1=1";

if (relIndice.getEventoId() != 0) {
    whereClause += " AND evento.id = " + relIndice.getEventoId().toString();
}

if (relIndice.getData1() != null) {
    whereClause += " AND evento.data_inicio_realizacao >= '" + relIndice.getData1().toString() + "'";
}

if (relIndice.getData2() != null) {
whereClause += " AND evento.data_inicio_realizacao <= '" + relIndice.getData2().toString() + "'";
}

whereClause += " ORDER BY evento.data_inicio_realizacao";

whereClause 3 IF, , WHERE, SQL.

"WHERE 1 = 1 , , .

ORDER BY, . , , , .

null zero ( eventoId, int), , SELECT WHERE... Coz !

, !

+2

sql, ...

select xxx
from <table>
where $P{eventoid} is null or evento."id" = $P{eventoid}

...

+4

Evento. "Data_inicio_realizacao" $P {data1} $P {data2}

( (evento. "data_inicio_realizacao" >= $P {data1} $P {data1} null) (evento. "data_inicio_realizacao" <= $P {data2} $P {data2} null) )

0

Source: https://habr.com/ru/post/1785566/