Jump to content
We've recently updated our Privacy Statement, available here ×

Subreports - how to combine 2 reports to make 1


magarwal

Recommended Posts

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/awardsListparent.jrxml[/file]
Link to comment
Share on other sites

  • Replies 5
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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".
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...