Hello,
Is it possible to write a conditional query in Ireport query executer? For e.g.: something like
IF $P{TEST_PARAM}.equals("test")
select query
ELSE
select query
END IF
Also the value for the parameter should come from the input control.
thanks for the help!
4 Answers:
Hi,
You can do this by simply using the following:
Suppose there is a parameter called $P{TestParamSQL}, the prompt should be turned off as we are setting the value at runtime checking the value of the $P{TEST_PARAM}.
Set the default value of the parameter as:
For a single condition
$P{TEST_PARAM}.equals("test") ? " select SQL query" : " else SQL select query"
For a multiple condition
$P{TEST_PARAM}.equals("test") ? " select SQL query" : $P{TEST_PARAM}.equals("test1") ? " SQL select query" : $P{TEST_PARAM}.equals("test2") ?" SQL Query" : "else SQL Query"
Now in the iReport Query executor you should give the following expression
$P!{TestParamSQL}
Do take care that the dependent parameter $P{TEST_PARAM}. should be set before the $P{TestParamSQL} else would throw a null pointer exception.
Another thing which should be kept in mind is that the query given in the quotes in the expression should be syntactically correct, that is the SQL in as the string should be correct.
Hope that this helps.
Thanks,
Ankur Gupta
Hi,
You can follow this video, created by me explaning the solution of your question
http://www.youtube.com/watch?v=tvddKCeWPBY
Thanks,
Ankur Gupta
http://ankurthetechie.blogspot.in/
can not at least that I know but can you pass a parameter query as armanda already and you can print it directly to the query would be something like
select *
from table1
where $ P {sql}
or wherever you need.