Home
Analytics
Conditional SQL statement and parameters
TheShadraq
I have a parameter called <em class='bbc'>fromSchedDate</em>. Based on what is entered, the SQL statement does 1 of two things. Below is the statement.<br />
<br />
The <em class='bbc'><strong class='bbc'>else</strong></em> works just fine. But if the <em class='bbc'><strong class='bbc'>If</strong></em> condition is met, nothing shows. I've pulled the statement into my SQL database and it works just fine. I must be missing something. Any help someone comes up with would be appreciated.<br />
<br />
I've attached the <em class='bbc'><strong class='bbc'>fromSchedDate </strong></em>setup below, in case it is relevant.<br />
Find more posts tagged with
Comments
mwilliams
If you comment out the if/else statement, except for the code within the "if" statement, does it work then?
Hans_vd
Hi,<br />
<br />
<blockquote class='ipsBlockquote' ><p><pre class='_prettyXprint _lang-auto _linenums:0'>if(fromDate == "1900-01-01")</pre></p></blockquote>
In this line you are evaluating a date variable against a string. You can't do that.<br />
<br />
Take a look at this few lines of code, the date parameter value is converted to a string that has the same format as the literal:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>importPackage( Packages.java.text );
var myDate = new SimpleDateFormat("yyyy-MM-dd", reportContext.getLocale());
if (myDate.format(params["dateParam"].value)=="2012-01-01") {
// do if stuff
}
else {
// do else stuff
}</pre>
<br />
As you are not really using the default date value, an even better solution could be to make the parameter optional and remove the default value. You can then check in your code if the parameter is empty by doing:<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>if (params["dateParam"]==null) {
// do if stuff</pre>
<br />
<br />
Hope this helps
TheShadraq
Okay. Thanks guys. I will work it and let you know what I come up with.
TheShadraq
Alright. I have tackled this from a number of ways and the only way I can get through this without an error is to simply change the parameter to <em class='bbc'>Data type: String</em> and use <strong class='bbc'>null</strong> instead of my turn-of-the-century date. <br />
<br />
Everything works just as expected if the dates are not null. The report shows blank if the dates are null. As per Mike's suggestion, I tested the report on simply the <strong class='bbc'>If</strong> statement as well and it runs just fine. The issue still seems to be hanging on my <strong class='bbc'>If</strong>.<br />
<br />
I even went through and removed all my <em class='bbc'>bisibility</em> entries in the Layout, just to be sure<br />
<br />
Any ideas?
TheShadraq
To get this to work, I employed Hans' idea of making the date not required. This allowed for a ligitimate <em class='bbc'>null</em> value.<br />
<br />
Thanks again for you help you guys.