I have 2 reports that work fine independently. Now I need to make 1 report by using these 2 reports as a master detail report. But it is not working. Both the individual reports are using queries to get the data. Can someone help me. [file name=awardsListparent.jrxml size=7830]http://www.jasperforge.org/components/com_joomlaboard/uploaded/files/awa...
5 Answers:
Posted on October 24, 2007 at 4:01pm
By default Jasper has only one query per report. To combine two reports into one you could create a main dummy report with a dummy query then place both of your reports in it as sub reports.
dummy query could be
SELECT O FROM duel
or whatever is supported by your database.
dummy query could be
SELECT O FROM duel
or whatever is supported by your database.
Posted on October 25, 2007 at 9:08am
Here is an example how you can do this (mini tutorial):
If you have, for example, database tables Departments and Employees, and you want your report to list the departments (master) with all employees in that department (detail), first create the master report with query:
SELECT d.deptName AS Name, d.id AS Id FROM Departments d
and put Name in detail band. Next, create a detail report with this query:
SELECT e.firstName AS FirstName, e.lastName AS LastName FROM Employees e WHERE e.deptId = $P{ID}
and define a parameter named ID in that report (set Prompt to true). Create the FirstName and LastName fields on the report. On the master report create a subreport in a detail band, define a connection (select "Use the same connection...."), for the "ID" parameter expression select the field "Id" from master report, choose a subreport dir (I always use parameter based value, but than you must supply the master report with the correct value for SUBREPORT_DIR parameter). That should work!
Pedja
If you have, for example, database tables Departments and Employees, and you want your report to list the departments (master) with all employees in that department (detail), first create the master report with query:
SELECT d.deptName AS Name, d.id AS Id FROM Departments d
and put Name in detail band. Next, create a detail report with this query:
SELECT e.firstName AS FirstName, e.lastName AS LastName FROM Employees e WHERE e.deptId = $P{ID}
and define a parameter named ID in that report (set Prompt to true). Create the FirstName and LastName fields on the report. On the master report create a subreport in a detail band, define a connection (select "Use the same connection...."), for the "ID" parameter expression select the field "Id" from master report, choose a subreport dir (I always use parameter based value, but than you must supply the master report with the correct value for SUBREPORT_DIR parameter). That should work!
Pedja
Posted on October 25, 2007 at 12:43pm
Basically I have to generate a report, which has a header and that information comes from a query. Then the actual report, and the data for that comes from a different query. So I need info as to how I can get this to work using subreports. How do I link the master and detail reports, is wat I cannot understand. Individually both the reports work, but together, the master report works but the subreport comes out empty.
Posted on October 25, 2007 at 1:32pm
I use the method described in my previous post, and never had that problem. I read in some other thread that someone had the same problem, and that it had something to do with subreport element properties Subreport Expression and Subreport Expression Class. In my case the class is java.lang.String, and the expression is $P{SUBREPORT_DIR} + "subReportName.jasper".