I am using the BIRT report writer, and I have multiple tables with the same data structure. In my report design, I want to select the table my query uses as a report parameter (as part of a mysql query in the data set) -- but I can't figure it out.
When I create the data set, it's great that I can use parameters in the form of SELECT * FROM WHERE ?, and set these to report parameters, but I get an error if I set the ? to the table, such as:
SELECT * FROM ? WHERE 1
Is there another way I can do this? As it's java, I assume the syntax follows that of a PreparedStatement. In BIRT 2.5 there is a property binding option under the data set dialog... and I've tried setting my query as: "SELECT * FROM "+params["DataTable"].value+" WHERE 1", but that was also results in an error.
I just answered this same question over at BIRT Exchange: http://www.birt-exchange.org/forum/designing-birt-reports/19097-set-query-table-using-report-parameter.html#post62590
I should note that the queries MUST return the same fields & data types after you modify them. I only note this because of your statement above that the table structure varies "a bit". It is perfectly safe to modify the FROM or WHERE clauses in a BIRT query, but you cannot modify the actual SELECT construct.
Related
I'm running Apex 19.2 and I would like to create a classical or interactive report based on dynamic query.
The query I'm using is not known at design time. It depends on an page item value.
-- So I have a function that generates the SQL as follows
GetSQLQuery(:P1_MyItem);
This function may return something like
select Field1 from Table1
or
Select field1,field2 from Table1 inner join Table2 on ...
So it's not a sql query always with the same number of columns. It's completely variable.
I tried using PL/SQL function Body returning SQL Query but it seems like Apex needs to parse the query at design time.
Has anyone an idea how to solve that please ?
Cheers,
Thanks.
Enable the Use Generic Column Names option, as Koen said.
Then set Generic Column Count to the upper bound of the number of columns the query might return.
If you need dynamic column headers too, go to the region attributes and set Type (under Heading) to the appropriate value. PL/SQL Function Body is the most flexible and powerful option, but it's also the most work. Just make sure you return the correct number of headings as per the query.
How can I use a plsql code block like this with an Interactive Grid (Using Oracle Apex) :
begin
Query A;
exception when no_data_found then
Query B;
end;
Actually sometimes 'Query A' returns nothing and I want to run 'Query B'. any solution?
An interactive grid has to use a sql-query as source.
a. Write one query and use sql-query as source:
SELECT * FROM A
UNION ALL
SELECT * FROM B WHERE COUNT(SELECT * FROM A) = 0;
b. Write some function which does the work
Read this:
How to return a resultset / cursor from a Oracle PL/SQL anonymous block that executes Dynamic SQL?
But it sounds a little bit strange, that you got one grid for two datasources. This will bring up some problems when manipulating the data.
Open questions
Do you want to modify the data?
Do you want to insert new rows?
Does the user understand what's going on and what he is seeing?
Since there is no apparent way to NOT use an SQL query as the Interactive Grid source, you could maybe (depending on your specific solution) think differently and create an Interactive Grid region for each query. Then you could show one or another when the page loads, using a region server-side condition or even a Dynamic Action.
To expand on other answers with a little specificity, since this is about managing results of 2 different queries, you can put the 2 different queries in 2 different Grid regions. Then on the first region add a Server-side Condition of "Rows returned" and copy the SQL Query into the query input provided. On the 2nd region, you would set "No Rows returned" condition and again copy Query 1 into the SQL input provided.
I'm new to Birt, so I might be doing this the wrong way...
What I need to do is to display some statistical data in reports.
Data will be prepared overnight in some special tables (I wanted to use materialized views, but haven't been able to find it in Birt report designer when connecting through JDBC to my DB - so I'll be using tables instead).
The typical chart I need to draw is :
- month on X-Axis
- a value on Y Axis.
For the Y Axis, there will be multiple series... But I don't know how many. Each serie data will be fetched from one of those special report table I was talking just above.
I have two main problems :
- how to display N series on a chart, N being unknown ?
- how to dynamize table names in a data set ?
Is there a more Birt-ish way to do so ? Maybe I have it completely wrong from the beginning, really don't know.
Thank you for your help.
Databases don't allow to dynamize table names with a regular query parameter, so we need to handle this by script.
The cleanest way would be to do this with a DB stored procedure: the BIRT dataset query just invokes a stored procedure of your DB with the table name as parameter. Here is an example of a such dataset query with MySql JDBC:
CALL `myschemaname`.`mystoredprocedure`(?);
Here, the question mark '?' is a query parameter, in the dataset editor we link it to a report parameter representing the table name. Then this stored procedure builds a dynamic query and returns relevant data.
Another option is to inject the table name in "beforeOpen" script of the BIRT dataset:
1- In your dataset, initialize the query with an arbitrary valid table name, for example:
select *
from myvalidtablename
2- In Eclipse designer select your dataset -> Script tab -> beforeOpen
Assuming the table name is in a report parameter:
this.queryText=this.queryText.replace("myvalidtablename",params["myTableNameParam"].value);
Concerning how to handle N series, it depends on how datarows are designed in tables. Two main cases:
Case 1 - Series are in multiple rows such:
month1;serie1;value
month1;serie2;value
month2;serie1;value
month2;serie2;value
This is the smartest case because it is dynamically handled in a BIRT chart with "Option Y series grouping". This is how this chart works: country field is set as optional grouping and BIRT handles everything.
Case 2 - Series are in multiple columns:
month1;valueSerie1;valueSerie2
month2;valueSerie1;valueSerie2
In this case we need to declare each serie explicitely. In the chart editor, by dropping down "Value (Y) series" menu we can create as many series as we like.
Currently I'm using Birt Report to generate report from my system. I'm using input parameter to send parameter from my system to Birt Report. The problem is when I'm trying to send multiple parameter from my system.
SQL statement at Birt Report for one parameter
select actualdate from table1 where storeloc = ?;
When I use this query for one parameter, it work.
I tried sql like this
select actualdate from table1 where storeloc = params["storeloc"].value;
I already created parameter at data set and report parameter but it's still can't gets to work
and also birt dont show me the options in edit dataset for query and Linked To Report Parameters in parameters
so what should i do?
Create a parameter storeloc in report params section of Data source.
Write this query in dataset open:
select actualdate from table1 where storeloc='"+params["storeloc"]+"';
Fetch the actualdate value in data source fetch and run the report.
I am writing queries for reports using Eclipse/BIRT. At the moment I create a query with ? characters for parameters, and I can then assign values to the parameters under the parameter tab.
However, if I need to assign the same value multiple times, I have to do this multiple times, once for each appropriate ?. Additionally, this system is fragile - if I add a question mark in the middle of the query, I need to adjust and reorder the list of parameters.
Is there a way to use named parameters rather than question marks in the original query?
BIRT query doesn't support named parameters but if database supports WITH statement, you can do what is illustrated here:
http://enterprisesmartapps.wordpress.com/2011/01/10/re-using-parameters-in-birt-data-set/
Basically, you're query becomes:
WITH
params AS
(SELECT ? AS year FROM dual)
SELECT * FROM tab1, params WHERE year = params.year
UNION
SELECT * FROM tab2, params WHERE year = params.year
Then you can set the ? once.