Jump to content

use the logicals operator in report expressions


francia

Recommended Posts

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

You can create a Boolean expression like these examples:

 

Variable myVar is a java.lang.String:

new java.lang.Boolean( $V{myVar}.equals("hello world") )

 

Field myFld is (say) a java.lang.Integer:

new java.lang.Boolean( $F{myFld}.intValue()>0 )

 

 

If you want to create an expression that actually performs an action based on a boolean comparison the you would do something like this:

 

new java.lang.String( $P{myParm}.intValue()=0 ? "Zero" : $P{myParm}.toString() )

Link to comment
Share on other sites

$P{} returns a quoted string like "hello", $P!{} returns an unquoted string like hello.

 

 

Unquoted strings are very important when placing parameter values inline with (say) and SQL query. Take the following valid example:

 

 

SELECT *

FROM mytable

WHERE mystringfield like '%$P!{someparametername}%'

 

 

and compare it to the invalid example:

 

 

SELECT *

FROM mytable

WHERE mystringfield like '%$P{someparametername}%'

 

 

If $P{someparametername} = "hello" then the first statement's like value will be '%hello%' and the second example's like value will be '%"hello"%'.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...