deepapriyan Posted July 14, 2012 Share Posted July 14, 2012 HiI have created a report which take From Date as an input Control Value.While declaring the dataType for this field gave the type as "Date".In my jrxml I have created a parameter $P{FromDate} as follows<parameter name="FromDate" class="java.util.Date"/>This field is not a mandatory field and can be left blank.If the user enters some value,based on that Date value I need to filter out my data and show in the report.So I am creating a conditional query statement to be added to my basic query.My problem is I am not able to check for the condition in the query whether $P{FromDate} is null or empty or have a value and form my query.Please help.This is urgent. Thanks In AdvanceDeepa Link to comment Share on other sites More sharing options...
cmatthews Posted July 14, 2012 Share Posted July 14, 2012 First of all in your query you would need to be using $P!{FromDate}The exclamation is required for the query. I think there are a lot of ways to accomplish what you are trying to do but here is one idea.Make the default value of FromDate be a known date in the future that would not be reported against like "'2199/01/01'", then check in your query if from date is equal to that date, something like this in sql server,If $P!{FromDate} = '2199/01/01'BEGINSELECT blah,blah,blah FROM blahContainerENDELSEBEGINSELECT etc,etc,etc FROM etcContainer WHERE dataDate BETWEEN $P!{FromDate} AND $P!{toDate}END Link to comment Share on other sites More sharing options...
deepapriyan Posted July 14, 2012 Author Share Posted July 14, 2012 HiThanks for the reply.In my case i am trying to add an extra condition to where clause of a query based on whether my date field is empty or not.So my conditional query is formed like this:-<parameter name="FromDate_SQL" class="java.lang.String"><defaultValueExpression><![CDATA[$P{FromDate}==null?"and s.time_slot >= to_date('2012-06-30','YYYY-MM-DD')" : "and s.time_slot >= to_date('2012-07-02','YYYY-MM-DD')"]]></defaultValueExpression> </parameter>Later in my actual query am doing the following :<queryString> <![CDATA[select * from detailTable where detailId =1 $P!{FromDate_SQL}]]></queryString>My problem out here is for checking whether the $P{FromDate} has some value entered or not or checking if there is a default value.In the conditional query that I am creating,I am always getting the value of $P{FromDate} as null.Please help. ThanksDeepa Link to comment Share on other sites More sharing options...
cmatthews Posted July 15, 2012 Share Posted July 15, 2012 I get what you mean, but would it work if you assigned the parameter $P{FromDate} a default value of an empty string "" and then you know what to expect when it has not been populated or selected. ($P{FromDate}.equals("")) ? "This" : "That"This way you don't need to worry about the default state of the object, you know it will either be an empty string or a date. So long as the paramters that refer to it are defined after it. The sequence/order of parameters and variables in the definition is important. Hope this is helping.Clark 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