Subreports - how to combine 2 reports to make 1

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...
magarwal's picture
222
Joined: Mar 1 2007 - 4:08am
Last seen: 16 years 7 months ago

5 Answers:

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.
svenn's picture
15124
Joined: Mar 19 2007 - 5:57am
Last seen: 16 years 6 months ago
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
Pedja's picture
2572
Joined: Oct 24 2007 - 6:31pm
Last seen: 15 years 11 months ago
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.
magarwal's picture
222
Joined: Mar 1 2007 - 4:08am
Last seen: 16 years 7 months ago
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".
Pedja's picture
2572
Joined: Oct 24 2007 - 6:31pm
Last seen: 15 years 11 months ago
I cannot use java.lang.string, cause we compile our jrxml file into a .jasper at run time and then store the .jasper in our database.
magarwal's picture
222
Joined: Mar 1 2007 - 4:08am
Last seen: 16 years 7 months ago
Feedback