Discussions
Categories
Groups
Community Home
Categories
INTERNAL ENABLEMENT
POPULAR
PUBLIC CLOUD
PRIVATE CLOUD
Quick Links
MY LINKS
HELPFUL TIPS
Back to website
Home
Intelligence (Analytics)
Dynamic WHERE clause not working
jmulders
I've searched this forum but still can't get my BIRT report working. I'm hoping someone can tell me where I'm going wrong.<br />
<br />
I have a report that prompts for a "Time Interval" of Day, Week, Month, Quarter, or Year. Based on the response, it should display transaction counts by that time interval.<br />
<br />
My data set looks like this:<br />
<br />
<p class='bbc_indent' style='margin-left: 40px;'><br />
SELECT<br />
<p class='bbc_indent' style='margin-left: 40px;'><br />
SUM(TRANS_SMRY.TRANS_COUNT) as Trans_Count,<br />
SUM(TRANS_SMRY.TRANS_COUNT)/1000000 as Trans_Count_Mlns,<br />
**** as Time_Interval<br /></p>
FROM<br />
<p class='bbc_indent' style='margin-left: 40px;'><br />
TRANS_SMRY,<br />
DATE_DIM<br /></p>
WHERE<br />
<p class='bbc_indent' style='margin-left: 40px;'><br />
DATE_DIM.DAY=TRANS_SMRY.TRANS_DATE<br />
AND DATE_DIM.DAY BETWEEN ? AND ?<br />
AND TRANS_SMRY.DATA_SOURCE_NAME IN ?<br />
AND TRANS_SMRY.REGION_NAME IN ?<br /></p>
GROUP BY<br />
<p class='bbc_indent' style='margin-left: 40px;'><br />
****<br /></p></p>
<br />
In the Before Open method of the dataset, I have the following code:<br />
<br />
<p class='bbc_indent' style='margin-left: 40px;'><br />
this.queryText=this.queryText.replace("****",switch (params["pTimeInterval"].value) <br />
case "Day":"to_char(DATE_DIM.DAY,'yyyy/mm/dd')";<br />
case "Week":"DATE_DIM.CAL_YEAR_NUMBER||' Wk '||to_char(DATE_DIM.CAL_WEEK_NUMBER,'09')";<br />
case "Month":"to_char(DATE_DIM.DAY,'yyyy/mm')";<br />
case "Quarter":"DATE_DIM.CAL_YEAR_NUMBER||' Q'||DATE_DIM.QUARTER_OF_YEAR";<br />
case "Year":"DATE_DIM.CALENDAR_YEAR_NAME";default:"");<br /></p>
<br />
When I preview the report, I'm getting an error:<br />
<br />
"There is a non-fatal error. There are errors evaluating script beforeOpen()."<br />
<br />
But there's nothing very specific in the error messages. Any ideas?<br />
<br />
Thanks<br />
Judy
Find more posts tagged with
Comments
mwilliams
In your initialize script, put QT = "";
In your beforeOpen, after your case statement, put:
QT = this.queryText;
In your design, after any element that uses the dataSet you put the beforeOpen code into, add a dynamic textbox and use the expression:
QT;
This should show you the value of your queryText, in your report. Does it look as it should?
jmulders
Michael, thanks for the suggestion, but it won't get that far. I added the code you suggested, but when I click "Preview Report", I get the error and then the report won't run.
I've attached a Word doc (*.docx) with a screen print of the error. Hope you can read it!
Judy
mwilliams
Try doing your switch statement outside of the replace() and then using a variable to store the value in to use in the function. You're probably getting some syntax error there.
jmulders
Hi Michael, I did try that, but couldn't get it to work. I might try it again. Thanks for the reply.
Judy
mwilliams
You also need to add a "break;" at the end of each case, probably.
jmulders
I did add a "break;" to the end of each case, but that didn't work either.
Now I'm trying dynamic visibility to show or hide charts (based on the value of a parameter). So far, that's working. It's klugy, but it works.
Regards,
Judy
mwilliams
Can you attach your actual report? I won't be able to run it, but I might be able to make any necessary changes anyways. Then, I'll just send it to you to test run!
jmulders
Hi Michael,
I've attached the version with the case statement. I added "break;" to each case, but that didn't work.
As I said, I had another version with a separate variable that was assigned the WHERE clause based on value of the parameter, then I concatenated that to the SQL statement, but that didn't work. (So the "switch" function was outside the "replace" function.)
Regards,
Judy
mwilliams
I don't see the report. Can you attach it again?
jmulders
Hi Michael,
I've attached the report.
Regards,
Judy
mwilliams
Try it like this:<br />
<br />
<pre class='_prettyXprint _lang-auto _linenums:0'>
temp = "";
switch (params["rpTimeInterval"].value){
case "Day": temp = "to_char(DATE_DIM_V.DAY,'yyyy/mm/dd')";
break;
case "Week": temp = "DATE_DIM_V.CAL_YEAR_NUMBER||' Wk '||to_char(DATE_DIM_V.CAL_WEEK_NUMBER,'09')";
break;
case "Month": temp = "to_char(DATE_DIM_V.DAY,'yyyy/mm')";
break;
case "Quarter": temp = "DATE_DIM_V.CAL_YEAR_NUMBER||' Q'||DATE_DIM_V.QUARTER_OF_YEAR";
break;
case "Year": temp = "DATE_DIM_V.CALENDAR_YEAR_NAME";
break;
default: temp = "";
}
this.queryText=this.queryText.replace('****',temp);
</pre>
jmulders
Haven't tried that yet, but if I have time, I'll try your code and update the topic. Thanks for the input.
Regards,
Judy