I have prepared a report in iReport, in which I am typing my values into my parameters. It is successful every time. When I have each parameter's default value to "" which essentially means that it will be empty.
Now when I put it into clarity, I have a drop down that populates with a query. when null, it shows ---. This is not matching the "" which is resulting in me having a blank project. I also tried changing the code too accept ---, however that was unsuccessful.
inner join NIKU.srm_resources on srm_resources.ID = prteam.prresourceid
AND (CONVERT(VARCHAR(100),srm_resources.ID) = $P{paramResource} OR '' = $P{paramResource})
if I do add a correct parameter (not leaving it null) then the report works fine.. Like i said, its just the null value that is giving me an error.
I guess my main question would be: What do these 3 dashes check against in the sql code rather than ''?
The assumption that exactly the visible text out of the drop down is sent to the report isn't right.
Presentation layer (JasperReport Server)
The Server checks that the parameter isn't mandatory. It provides this record with three dashes for the user to be able to select empty / null.
If the user selects the three dashes, JasperReport Server will send null
to the report.
If the user selects any other value, JasperReports will send the value defined in the Value
column of the server.
Backend (Predefined report)
The JasperReport Server sends a value no matter what default value you have provided in the field. So if no field is selected (three dashes), you will get null
. If anything else is selected, you will get that value as a parameter value.
When setting default values those are only being used if no parameter component (input component) will be set in JasperReport Server.
Conclusion
The three dashes will never reach the SQL. The parameter will either be null
or provided with the value you selected in the drop down.
EDIT
If you want to be able to interpret both cases, you should change the order of the OR
and use IS NULL
, otherwise the first comparison will always be checked (even with null
values):
... AND ($P{paramResource} IS NULL OR (CONVERT(VARCHAR(100),srm_resources.ID) = $P{paramResource}))