Jasper report to call two independent queries and display results in one report - jasper-reports

Similarly i have an requirement that, in one main excel report should have tittle only, and then need to call two independent queries and display the results below the tittle. Just need to send counts of records from both queries to main report.
I don't want to repeat the results just display once.

Thats basically what subreports are for. You can create one JRXML-report which contains two child (sub)reports. Each subreport can have its own Query.
PS : The detail Band is rendered once per Resultset. So maybe it is enought to use this.

Related

my table jasper report repeat the data many time [duplicate]

I am new to JasperReports, basically I want to put a subreport in a mainreport
The problem is that I put the sub report in the Detail band, so when I query a database that has multiple data the subreport will always repeat itself multiple times when I output the report to a pdf. I want a report that does not repeat itself regardless of how many data I have in the database that i connect with
I have searched the Internet and the solutions is to add
new Boolean($V{REPORT_COUNT}.intValue()==1)
in the print when expression attribute of the subreport, that does solve a part of my problem due to the fact that now my subreport only prints once but it still leaves some blank pages after my subreport is displayed
So I assume it is still repeating itself but just doesn't print the data because of the expression that I added , people say that the nature of the detail band is supposed to work that way and that I shouldn't put the subreport in the detail band, but if I put it in some other band I get this error:
Error filling print... Subreport overflowed on a band that does not support overflow.
The error above will happen if I have a lot of data to the extent that it may take up more than a page.
How do remove those blank pages? If I am ask to not put it in a detail band then what should I do? or what solution are there?
The Detail band will be generated as many times as the number of records you have in your main dataSet(populated by the top-level query).
If you want to keep the subreport in the Detail band, which is normal by the way, you can do one of these things:
either have a dummy query that returns only one record, so that the Detail band generates only once. Then, pass the report connection to your subreport. You may have done that already. This way you can run your query independently of the main report.
or leave the report as-is and add your printWhen expression ($V{REPORT_COUNT}.intValue()==1) directly on the Detail band, not on the subreport. Please note that this is just an ugly hack that may affect the report performance. Your main query still returns a lot of data that you don't use so you should consider the other options.
If you can move the subreport out of the Detail band, place it in a band that allows overflow like Title or Summary band. Then:
have your main dataSet's query empty so that no Detail band gets generated
set whenNoDataType="AllSectionsNoDetail" at the report level(in the <jasperReport> tag) so that all the other sections except the Detail get generated
exactly as in the first option above, pass the report connection to your subreport and work from there

Crystal Report with multiple datasources

I am working on a crystal report like in the sample image. it has some limited attributes and some attributes that will be repeated. like item id will be repeated for each item and invoice id will be only one in the whole invoice. I am trying to use two different tables one for repeating elements and one for single time elements.
I am facing problem in setting the datasource of the crystal report. how can I set it so that it may fetch data for repeated elements from datatable one and other from datatable two.
Or if you know any other approach for such problem please share.
Problem Solved.
We can use as many datasources as we want. We just need to add them through database expert options.
besides while giving it actual data we can do that like this:
objRpt.Database.Tables[0].SetDataSource(list_of_objects_of_data_sources);
objRpt.Database.Tables[1].SetDataSource(list_of_objects_of_data_sources2);
this also shows that we can provide data to crystal report through list of obects instead of datatables. we just need to set the references in the database expert as those class objects.
like in the figure

subreport in Detail band getting displayed repeatedly

I have a subreport included in the Detail band of the parent report. The SQL query in the parent report returns multiple rows. And so my subreport also gets displayed as many times as the records returned by parent SQL query. I want to display subreport only once irrespective of the records returned by SQL query in parent report. I have tried moving subreport to columnfooter section but then i get a "Subreport overflowed on a band that does not support overflow" error.
Any pointers to get it working will be really helpful.
Ok to start with: a subreport has a different Dataset (SQL query) then the parent report. If you use an query, the subreport is shown as many times as there are records as a result of the query. This is actually what it's meant for and that's the same as with parent reports.
What you want to achieve if I unerstand you correctly, is that you have the supreport outputted once and the main report outputted as many times as there are records returned. What I would suggest is:
Why don't you turn it around? Would solve all your problems and you use the programm as how it's meant to. You can do it like this:
Put the query that returns mulptiple record in a subreport, change layout so it matches your current parent report.
Put the data that should be displayed only once in you parent report Query (LIMIT bij 1 if it can return multiple records but you need the first). And put the necessary textfields etc. in the main report before or after the subreport.
Hope it helps! Let me know

How to use Details band to display multiple data sets

I have a JasperReports's report with 10 rows fetched from the main query..
When i run the report it will show 10 rows without a problem.
Now when i add another band with fields of a data set in a list item. It is repeated for every record in the main report!. :(
How can i avoid this situation and change the second details band to print when the main report data has finished printing on the first band?
I would want to achieve this without going for sub-reports as it's difficult to maintain many files for a single report.
I have learned a lot on jasper reports over time and I'm posting the answer for my very own question to help someone in future.
What you need to do is for complex, Multi-query reports you create the main report with a simple query like this.
SELECT SYSDATE FROM DUAL
What this means is that when it's run main report details band will have a single iteration. That means if we have used the SYSDATE field in the details band it will print once.
OK, now if you follow the following steps you should be able to achieve the above task successfully.
Add two details band to the report (you must be having one details band by default, to add another right click --> add another detail band)
Add two data-sets to the main report (right click on the report and select Add Dataset)
Now all you need to do is use those two data sets in the previously created details bands by using either a list item or table item (personally I would recommend table as you can do lot of advanced stuff in that)
Hope this will help someone in the future. let me know if you need more help!. Cheers!!

Multiple Crystal Report to be printed on same report

I have a crystal report that takes only about 1/3rd of the report space.
I have field read from the database which is an integer value.
I wish to print this report number of times as read from the database on the same page.
Any idea on how this can be achieved?
I can only use crystal report for achieving this.
Thanks in advance.
You can create another report and add your current report as a subreport multiple times
Lan is correct, build another report and add your current report as a subreport.
Here's the trick:
On your main report, have it make a list of all of the items that
you'd like to run the sub-report on.
On your sub-report, add a parameter called "itemNumber" or something like that. Then change your Subreport Links so the new "itemNumber" parameter is linked to the item on your top level report.
Now hide the field on the main report but leave the
subreport visible.!
This should make your report run for all items at one time.
In this case you can create a table with the maximum number of prints you will ever use. For example if you think you might need to print the report 100 times your table should contain records from 1 to 100. So lets assume this is the case- create a table , name it Copies and add a field CopyNo. Create a 100 records and set CopyNo from 1 to 100. Create the a main report based on Copies table - the record selection formula will be something like :
Copies.CopyNo<=#NumberOfCopies
#NumberOfCopies is a parameter , which you can set in order to control the printed copies. Create your actual report as a subreport and place it in the details section of the main report. When you run the report it will ask you for the number of copies and when you insert it, will print the same subreport as many times as the number you provide.