Jump to content

Issue with passing null value as parameter value


nairsunil

Recommended Posts

I am facing some issues when we pass in null as value for the parameter in the query.

 

 

Query Executed by Jasper when we pass in the parameter Business Unit

 

select *

from tx_acct_details_merged

where BUSINESS_UNIT = $P{param1}

 

It executes

select *

from tx_acct_details_merged

where BUSINESS_UNIT = null

 

Returns me 0 records

Correct Query

 

select *

from tx_acct_details_merged

where business_unit is null

 

Returns me 10 records

 

How do I dynamically change the query to replace BUSINESS_UNIT = $P{param1} with BUSINESS_UNIT is $P{param1} in case the value for $P{param1} is null?

Link to comment
Share on other sites

  • Replies 3
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

As acer said, you can use the $P!{..} to switch between the two types of where clauses:

Code:

<param name="param1" .../>
<param name="param1Clause" isForPrompting="false">
<defaultValueExpression>$P{param1} == null ? "IS NULL" : "= $$P{param1}"</defaultValueExpression>
</param>
<queryString>... where BUSINESS_UNIT $P!{param1Clause}</queryString>

 

Note that this would only work in JR 1.3.2 or later. If you use an older version you would need to do instead

Code:
[code]
<param name="param1Clause" isForPrompting="false">
<defaultValueExpression>$P{param1} == null ? "IS NULL" : ("= " + $P{param1})</defaultValueExpression>
</param>

or, if your param is a String

Code:
[code]
<param name="param1Clause" isForPrompting="false">
<defaultValueExpression>$P{param1} == null ? "IS NULL" : ("= '" + $P{param1} + "'"«»)</defaultValueExpression>
</param>

 

HTH,

Lucian

Post edited by: lucianc, at: 2007/06/19 05:29

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...