A database field named income_source
is queried using:
SELECT * FROM table_name WHERE income_source LIKE "salaried%"
This retrieves income_source
values with a "salaried" prefix. In iReport, the PrintWhenExpression value for the field is set as:
$F{income_source}开发者_StackOverflow.equals("Salaried")? Boolean.TRUE:Boolean.FALSE
Why does the report output differ from the SQL output?
There are a few problems:
- The value
"salaried%"
in the SQL differs from the value of"Salaried"
in the expression. - The value
"salaried%"
uses the%
to match all text after the letterd
. - There is a bit of redundancy in the PrintWhenExpression.
Try the following expression:
$F{income_source}.startsWith( "salaried" )
Or:
$F{income_source}.trim().toLowerCase().startsWith( "salaried" )
One of those should work. You will also want to ensure Blank when null is checked. Otherwise, the expression becomes:
$F{income_source} == null ? Boolean.FALSE :
$F{income_source}.trim().toLowerCase().startsWith( "salaried" )
精彩评论