nairsunil Posted June 14, 2007 Share Posted June 14, 2007 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 executesselect * from tx_acct_details_merged where BUSINESS_UNIT = null Returns me 0 recordsCorrect 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 More sharing options...
acer Posted June 14, 2007 Share Posted June 14, 2007 weird problem why dont you set your parameter "= null" it should work...i think check this out http://jasperforge.org/sf/wiki/do/viewPage/projects.jasperreports/wiki/Tutorial_Parameters especially this SELECT * FROM Orders ORDER BY $P!{OrderByClause} Post edited by: acer, at: 2007/06/14 07:45 Link to comment Share on other sites More sharing options...
nairsunil Posted June 16, 2007 Author Share Posted June 16, 2007 Passing param = null gives you different results in oracle. select x , y , zfrom table where x is nullgives different result thanselect x , y , zfrom table where x = nullThis is the problem i am facing. Any help Link to comment Share on other sites More sharing options...
lucianc Posted June 18, 2007 Share Posted June 18, 2007 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 insteadCode:[code]<param name="param1Clause" isForPrompting="false"> <defaultValueExpression>$P{param1} == null ? "IS NULL" : ("= " + $P{param1})</defaultValueExpression></param>or, if your param is a StringCode:[code]<param name="param1Clause" isForPrompting="false"> <defaultValueExpression>$P{param1} == null ? "IS NULL" : ("= '" + $P{param1} + "'"«»)</defaultValueExpression></param> HTH,LucianPost edited by: lucianc, at: 2007/06/19 05:29 Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now