I am working on Jasper Reports and my query uses SQL 'IN' predicate.
SELECT customer_name AS NAME,
id_customer AS ID
FROM customer
WHERE customer_role IN ($P{roles})
Here the role parameter can have 1 or more integer values and will be dynamically decided when generating the jasper report.
Can anybody please help me on how to set the value of 'roles' parameter thru Java program dynamically.
Jasper Report has a special variable $X for that:
select * from customer where $X{IN,customer_role,roles}
should work. See here and here.
The examples linked to in the accepted answer don't come up for me.
An alternative that worked for me is instead of using:
...
WHERE customer_role IN ($P{roles})
I used this:
...
WHERE customer_role IN ($P!{roles})
And for the roles variable I pass in a String containing one or more values, each in single quotes, separated by commas (e.g., '1','2','3').
See here for reference.
To complement #Aaron response, you can configure a list parameter ("roles" in your case) within JasperSoft Studio as follows:
Related
Does anyone know how to define a parameter in Jasper Studio (Community version 6.3.1 final) that is a collection, such as a Set, and to use that in a postgresql query? For example, this Set could be a set of ids that would then be used in the query.
I do a simple sql query like:
select pg_typeof($P{companyDepartmentIds}) as type
I get the following error after selecting "Read Fields":
It seems like this should be possible, I feel I am missing something. I am not sure where in the Jasper Studio interface I can call this setObject() function. Anyone have any thoughts here?
If defining a collection of parameters can't be done, the only other thing I could think of is I could have the parameter be a String, but it would be understood it would be a comma delimited list of values, then I could use regexp_split_to_table or regexp_split_to_array within the query itself.
I was directed to this link and saw what I needed here:
https://community.jaspersoft.com/blog/tip-multi-select-query-integer-parameter-japser-ireportstudio
Specifically what I was looking for was this part from the website under the "Correct Way:" example
SELECT * from table where $X{IN,id,companyDepartmentIds}
For my College assignment, I have to create a database in Access, I have done 99% of my database, apart from this section which I'm stuck on.
In my DB, I have a tickets table, which contains records on order information and a field containing a date. For my assignment, I have to create a Form which reads from a Query.
For example, in my Form i have already created i have 2 Combo boxes with the dates already pulled from the Query. I need to be able to drop down one of the boxes and input 1 date, and then drop down the other box and select a different date, press a button and it generate me a Report.
The part I am asking for help on is the expression which is used to look up the data inside the Query. I tried using this expression, which Access said was too complicated.
[Forms]![frmOrdersBetweenTwoDates]![Combo33] And [Forms]![frmOrdersBetweenTwoDates]![Combo36]
My full SQL query is:
SELECT tblTickets.CustomerID, tblCustomers.FullName, tblCustomers.AddressLine1, tblTickets.OrderNumber, tblTickets.OrderDate
FROM tblCustomers INNER JOIN tblTickets ON tblCustomers.[CustomerID] = tblTickets.[CustomerID]
WHERE ((("WHERE [OrderDate]") Between [Forms]![frmOrdersBetweenTwoDates]![Combo52] And [Forms]![frmOrdersBetweenTwoDates]![Combo54]));
My expression/query now returns the report, but there is no data inside the report. How could i fix this?
Cheers.
Should post the complete query statement. Expect the filter clause should be like:
WHERE [date fieldname] BETWEEN [Forms]![frmOrdersBetweenTwoDates]![Combo33] AND [Forms]![frmOrdersBetweenTwoDates]![Combo36]
However, I don't use dynamic parameterized queries. I prefer to use the WHERE argument of OpenReport (same for OpenForm), in VBA:
DoCmd.OpenReport "report name", , , "[date fieldname] BETWEEN #" & Me.Combo33 & "# AND #" & Me.Combo36 & "#"
I publish a report in jasper server.The report contains two parameter, customer_id and query. The parameter query is an array and its class is java.util.List. The report is working in jasper soft studio. But i cant set parameter in jasperserver please refer the below image
How can i set array parameter in that query field?
You should set java.util.Collection instead of java.util.List as the class if you want to multi-select list values.
Refer to this link for detailed instructions.
If you wanna just have single select from the list then set the class to String or number.
I am working on Jasper Reports and my query uses SQL 'IN' predicate.
SELECT customer_name AS NAME,
id_customer AS ID
FROM customer
WHERE customer_role IN ($P{roles})
Here the role parameter can have 1 or more integer values and will be dynamically decided when generating the jasper report.
Can anybody please help me on how to set the value of 'roles' parameter thru Java program dynamically.
Jasper Report has a special variable $X for that:
select * from customer where $X{IN,customer_role,roles}
should work. See here and here.
The examples linked to in the accepted answer don't come up for me.
An alternative that worked for me is instead of using:
...
WHERE customer_role IN ($P{roles})
I used this:
...
WHERE customer_role IN ($P!{roles})
And for the roles variable I pass in a String containing one or more values, each in single quotes, separated by commas (e.g., '1','2','3').
See here for reference.
To complement #Aaron response, you can configure a list parameter ("roles" in your case) within JasperSoft Studio as follows:
I have a report which creates a list of Events for a specified date range and event type.
The date range and event type are parameters defined in the report. The date parameters (#DateFrom and #DateTo) work as they should.
The #EventType parameter however, which is defined as a list of values provided by a DataSet (with 'Allow Multiple values' checked), does not provide the expected behaviour when using the {Select All} check box. If I select one or more Event Types by checking several boxes on the list, the report will show the Events which match the specified Event Types correctly.
However, if I click the {Select All} box (which then highlights all of the other possible values), the report does not show the Events for all of these Event Type values. It seems to miss out several of the values which are selected by the {Select All} box. If I run the report specifically for those missing values, the report returns events matching those types. This indicates to me that there is not a lack of data for these types.
And for that reason, it looks to me like the {Select All} is bugged...or perhaps cached somewhere? I've tried deleting the report/parameter dataset and redeploying to no avail. It's worth noting that this behaviour happens locally before deploying it, too.
Has anyone seen this before, or does anyone have any suggestions?
EDIT - I should also mention that the parameter in question (#EventType) has no default value assigned.
How are you declaring your predicate for the variable? It should be be like:
where thing in (#Variable)
Where #Variable is a multi value parameter.
You could attempt to see if the values of the multi valued parameters are junked up somewhere as well by defining them. Generally the collection method of multi valued parameters can cause issues if there data types are different.
Also you may try to design your data set at runtime to build instead of being a static query. EG: Set up an expression for your dataset like:
="Select * from table where thing in (" & Parameters!Variable.Value & ")"
This would cause the parameter to build as part of a string and then evaluate at run time instead of from a traditional query.
Can't quite believe that this was the case, but the parameter which was passed to the SQL Server procedure was too small. It was defined as a VARCHAR(500) and needed to be bigger to deal with a large list of comma separated values. I changed it to VARCHAR(4000) and it's now functioning as expected.
Thanks to Djangojazz for pointing me to the direction of the parameter.