Reputation: 1611
I'm trying to create Sub Report in Jaspersoft Studio 5.5. My table structure is like below:
DEPT(DEPTNO, DNAME, LOC)
EMP(EMPNO, ENAME, SAL, DEPTNO)
Main Report name: MainReport.jrxml
Sub Report name: SubReport.jrxml
I have tried like below.
Created one row in the "Main Report" by passing parameter for DeptNo.
Now, Dragged Subreport component from Palette on to the main report.
Selected "Create a new report" option from "Subreport" wizard.
Tried to write the below query to get Employees from the Active Department. Problem started from here onwards. I could not understand how to supply the parameter to get the parent DEPTNO
SELECT EMPNO, ENAME, SALARY FROM EMP WHERE DEPTNO = 10
In the above code, I've Just hard coded DEPTNO = 10
to complete the query. This is where I want support from experts to know how to replace DEPTNO = 10
with the parameter
Upvotes: 0
Views: 230
Reputation: 3167
Assuming that you have a main report with a promted parameter and you want to "pass" it to the subreport, when you create the subreport - in the parameters section - you have to add that parameter (in addition to the defaults) in order to make it "visible" to the subreport.
EXTRA: if the "active department" is something you get from a query (let's say "select deptno from DEPT where active = "Y"), you should "pass" THAT VALUE ($F{DEPTNO}) as parameter to the subreport.
Then in the subreport query, you have to replace your hardcoded value with the parameter, something like this:
SELECT EMPNO, ENAME, SALARY
FROM EMP
WHERE DEPTNO = $P{YOUR_PARAMETER}
Maybe this tutorial from jaspersoft community could visually help you.
Upvotes: 1