Use multiple data sources within a Jasper report - jasper-reports

I have a Jasper server, which holds some reports. These reports I can access by the Rest interface (https, get). One of the reports should return some data from an Oracle database, where data are stored into multiple schemas. The schemas have an identical structure.
select * from schemaA.tableX
displays the data from schemaA. Now I have to change the report data source:
select * from schemaB.tableX
to display the data from schemaB (structure of tableX is the same as in schemaA). I would like to configure my report with a parameter, to switch between the schemas (there are a lot of such schemas into the database).
Is it possible to change the schema name within the report dynamically or can I change the datasource definition of the report using a report parameter? I would prevent n identical reports on the Jasper server which only differ in the datasource definition.
Thank you.

Related

Use SQL Select directly in CR Function

There's a working report but I wan't to change the visibility of certain rows based on a completely new DB select that should be executed when the report is created.
It would be ideal, if I could load the values of said select in an array or a list and than simply trigger certain row's visibility by comparing e.g. the Row Id with the values in the array.
Im used to solve a problem like this by creating a View that delivers all the essential information in each row and is used as the main data source but I was wondering if there's an elegant way within crystal reports to solve such a task.
I can think of three ways to include control data like this into the report:
One row of config data: If you can arrange it that your config data query returns one row of data, it can be just added to the data sources of the main report, without any links to tables and views already there.
Config resultset for matching: If you have to match main data results to config values row by row, e.g. by the Row Id you mentioned, add this config query to your report and link it to the main data source accordingly. (You are probably already doing this within your pre-created view on database side.)
Query config by subreport: Most flexible but also time consuming option is to add a subreport in report header, add the config data query and arrange config results into (shared) variables as needed in the subreport. Shared variable values can be used in main report then to control section visibility.
Yes, one of the 3rd-party Crystal Reports UFLs (User Function Libraries) listed here provides such a function.

How to link datasets in jasper report without using tables or subreports

I have two SQL tables.Data is in one table and the columns for the report is in another table.Therefore I want to use multiple queries in my report and I am doing this by creating a new dataset.Now I wanted to pass the result of my main query to the query in the dataset.Is there any method to link these?Logically there is no relation between my two tables because one table is a common table for storing values of my entire project.Please help...My project is delayed with this problem.

Multiple databases in Crystal reports

I have 10 Postgres Databases linked via ODBC which I use in Crystal Reports.
These 10 databases are all the same, same schema and tables.
The 10 databases I need to query from all at the same time, to have one consolidated report. Is this possible? If so, how can i Link the databases to have consolidated data?
I will be using a SQL query to draw the data.
Thanks in advance
The right way will be to handle the datasource outside Crystal reports. I am not familiar with Postgres , and I don't know if you can link tables or databases. In SQL server you can use linked servers, in MS Access linked tables, there should be a similar concept in Postgres. The idea is to link an object outside the databse and use it inside the database. This will allow you to prepare a query like this:
select A,B,C FROM server1.database1.table1
UNION
select A,B,C FROM server2.database1.table1
UNION
select A,B,C FROM server3.database1.table1
...
UNION
select A,B,C FROM server10.database1.table1
This query ( or view) will contain all the information and you can base you Crystal report on it. Crystal will work with just one database , the one which contains the query, and the query will deal with the other databases to collect the data. This will be way faster compared to the method when you add your connections to all 10 database directly to Crystal reports.
I don't think subreports are an option here . Each subreport will connect to a separate database and you will get 10 separate subreports. You may get all the data but it will be sorted for each subreport, so you will have A->Z for the first databse then A->Z for the second and so on. Ther will be 10 separate sets of data , which will be presented together but will still behave like separate recordsets.
If Postgres does not support linked databases you can use an Access database as a proxy , just link your tables and use it as a place , which will combine the data

Create Formula Field that Lists All Tables In Crystal Report

I am looking for a way to create a formula field that will list out the table names of all tables that are being utilized as data sources in a Crystal Report.
I have not found any function that provides that capability in the application yet.
This would be used to put the list of tables as a supplemental for those users that do not have access to the report file but need to know what tables are used in the report.
It seemed better to do this as dynamically as possible - instead of having to provide a static list of current tables linked into the report.
Thanks.
Unfortunately, this type of functionality isn't present in Crystal Reports.
You might be able to use a UFL to solve the problem. General idea:
pass path of current report to UFL (the Filename function will give you this)
open the referenced report using the Crystal Reports SDK and examine the tables in DataDefintion class; the DatabaseFieldDefinition.UseCount will help determine if a field (and hence table) is referenced in the report
return the table names as a string array (note: CR only supports 1-dimensional arrays w/ a maximum of 1000 elements)
create a formula field to call the UFL's function; Join() the string array (formula fields can't return an array):
Join(GetRptTables(Filename), ",")
distribute the UFL with the .RPT
Another option, if you have BusinessObjects Enterprise and a spare $40K, is Metadata Manager; this will give you a holistic view of your organization's reporting deployment.

Can crystal reports get data from an object data source?

Can crystal reports get data from an object data source instead of a database? I am using the crystal reports that comes with vs2008. I am coding in c# 3.5.
I would like to use an object data source that returns a List< MyClass>.
For when we migrate to ssrs in the future, Can ssrs 2008 get data from this object data source ?
SetDataSource has an overload excepting ICollection parameters. Using it, you can bind simple collections of objects to CR. But this isn't that flexible than using data sets. With data sets you can bind multiple related tables and build reports of a higher complexity.
The migration of your server has no impact on CR, because SetDataSource only works with disconnected objects such as data sets or object data sources.
Yes you can do that, but you have to wrap the objects in an array :
// my crystal report
Rpt rpt = new Rpt();
AirLine lAirLine = (AirLine)cmbAirLine.SelectedItem;
// I added two objects as datasources in report designer
// here aWB.AWBPieceList is List<AWBPiece> where 'AWBPiece' is some class.
rpt.Database.Tables[0].SetDataSource( AWBPieceList.ToArray() );
// the second : objects are mapped to tables by crystal report.
rpt.Database.Tables[1].SetDataSource( new AirLine[] { lAirLine } );