How I create a parameter $P{} where the expression is $p{}==1?$p{}=26:$p{}=0

Hi, I created a report with ireport 5.6 , this is by compatibility with java 7 and DBF. I try to do the folow:

my query is:

Select *

from table

where field_in_table = $p{parameter_name}

I need the folow:  $p{}==1?$p{}=26:$p{}=0
 (IF(parmeter==1) true value parameter =26, false value parameter=0)

I tryed writed in default  value expression of the parameter and there is a error, i writed:
 $p{}==1?$p{}=26:$p{}=01?26:0 and not run the report,
too 1?26:0 run the report but no filter in the query sql.
I tryed with $p{}.intValue==1?26:0
and with $p{}.intValue==1?$p{}.intValue=26:$p{}.intValue=0 there is error.
How can I make the parameter change its value so that it is filtered by the expression WHERE of the query in sql.
Thank.'s picture
Joined: Sep 13 2017 - 6:59pm
Last seen: 6 months 1 week ago

Give the below a try -

Boolean.valueOf($p{}==1) ? 26 : 0

So what the above will do if your parameter equals 1 then return 26 else 0

luked - 3 years 7 months ago

You can not set the value of the parameter in the conditional (ternary) operator.

Try the way that @luked comment. 

I am Leo - 3 years 7 months ago

try to move the logic to sql

trvpseudo - 3 years 7 months ago

1 Answer:

u cant add logic in parameter default expression, coz default expression will be overwritten by the time user give an input.
try to add logic into ur SQL instead :

select *
from [table_name]
where [column_name] =  (case when $P{param_name} = 1 then 26 else 0 end)

u can put the logic to variable. but i hvnt tried adding variable to the SQL.
regards, TV

trvpseudo's picture
Joined: Jan 30 2019 - 11:02pm
Last seen: 4 months 4 days ago