Tuesday, July 24, 2012

Jasper report Pass SQL to report as parameter

In jasper report, parameters can be categorized into a few data types. According to the data type, parameter  value is attached single quote.

For example, parameter data type is String, it is attached single quote (') between parameter value.
In some cases, we have to pass whole SQL to jasper report to generate report.

If we sent the SQL as a parameter it will return error, because of adding single quotes to parameter.
Solution is to have a ! sign before the parameter value as shown is below.

If the parameter value is "Query", it can be avoided adding single quote to parameter like below.

$P!{Query}

NOTE :- SQL can be a normal SQL statement