I've two JRXMLs. One is the main report and the other is the subreport.
In the main report I've a query like
select name, address, phoneno from Employee where id=$P{id}
So I've added the id to my Parameters
in the main report and it will prompt for the id when I preview the report.
Now in the subreport, I would need a query like
select age, bloodgroup from Employee where id=$P{id} and name=$P{name}
The where clause name should be taken from the main report.
I would not need another prompt like id for the name.
So how to pass the parameter value from main report to subreport?
In your main report you have to "pass" all the parameters you need to the subreport.
Let's assume that in your main report you want to pass the CITY parameter to your subreport, you should have something like this code:
<subreportParameter name="City">
<subreportParameterExpression><![ CDATA[$P{City} ]] ></subreportParameterExpression>
</subreportParameter>
In addition to this, you have to add the same parameter in your subreport (parameters-section).
Note that in the CDATA section you can have more than one parameter and you can pass parameters ($P{parameter_name}) or fields ($F{field_name}) as well
Hope it could help!