Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

passing SQL "IN" parameter list in jasperreport

I am working on Jasper Reports and my query uses SQL 'IN' predicate.

SELECT customer_name AS NAME, 
       id_customer   AS ID 
  FROM customer 
 WHERE customer_role IN ($P{roles})

Here the role parameter can have 1 or more integer values and will be dynamically decided when generating the jasper report.

Can anybody please help me on how to set the value of 'roles' parameter thru Java program dynamically.

like image 299
Priyanka Avatar asked Jun 03 '11 11:06

Priyanka


1 Answers

The examples linked to in the accepted answer don't come up for me.

An alternative that worked for me is instead of using:

...
WHERE customer_role IN ($P{roles})

I used this:

...
WHERE customer_role IN ($P!{roles})

And for the roles variable I pass in a String containing one or more values, each in single quotes, separated by commas (e.g., '1','2','3').

See here for reference.

like image 164
Woodchuck Avatar answered Sep 19 '22 21:09

Woodchuck