rym
rym

Reputation: 545

Passing a variable and query to Jasper report

Is it possible to pass both an SQL query, e.g. (<![CDATA[$P!{SQL}]]>), and a variable $V as parameters to a Jasper report at the same time?

Also, how can I pass the variable $V to my Jasper report using Java?

Upvotes: 0

Views: 3372

Answers (2)

Andreas Covidiot
Andreas Covidiot

Reputation: 4755

Often it is desired to just transform some parameter in order to use it in a query (in this case, the following works :) ).

E.g. (pseudo code - Groovy syntax!)

parameter:

filtParamUserName = "foo"

"variable" (technically not: in this case another parameter following it)1:

sqlCondUserName = $P{filtParamUserName} ? " and user_name = '$P{filtParamUserName}'" : ""

thus you could easily use it in your query like:

select * from bar where 1=1 $P{sqlCondUserName}

1: you have to set the Default Value Expression of the sqlCondUserName and Is For Prompting = false

Upvotes: 1

JB Nizet
JB Nizet

Reputation: 691655

A variable is something that varies during the report generation, like the number of pages for example. So a variable ($V) is not something you can pass to a report. You may pass any value from your Java code to the report as a parameter ($P), though.

Upvotes: 0

Related Questions