0

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.

  1. Created one row in the "Main Report" by passing parameter for DeptNo.

  2. Now, Dragged Subreport component from Palette on to the main report.

  3. Selected "Create a new report" option from "Subreport" wizard.

  4. 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

1 Answer 1

1

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.

2
  • Hi Fabio, Thank you very much for your reply. I will verify this article right now. The above link points to just one topic. Could you please suggest me the URL where I can get all topics like above! I am asking you this since I am extremely new to Jaspersoft Studio. I've verified the parent URL of the above URL, but it didn't work as number of links are there. Thank you once again. Jan 19, 2016 at 13:08
  • as far as I understand, it seems like you're really close to accomplish what you need. you just need 2 steps: 1) pass the parameter to the subreport (as shown in the article and suggested before) 2) modify the query of the subreport with that parameter... in case you need it, here's a tutorial to handle parameters: community.jaspersoft.com ... was the answer clear? Jan 19, 2016 at 14:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.