原标题:How do I set a parameter to a list of values in a BIRT report?
我有一个数据表,有这样一个问题:
select s.name, w.week_ending, w.sales
from store s, weekly_sales_summary w
where s.id=w.store_id and s.id = ?
我愿修改询问,以便让我具体说明一份储存识别清单,例如:
select s.name, w.week_ending, w.sales
from store s, weekly_sales_summary w
where s.id=w.store_id and s.id IN (?)
我如何在BIRT中做到这一点? 我需要具体说明哪些参数?
最佳回答
报告参数很容易部分:将显示类型定为清单箱,然后检查“允许多价值”办法。
Now the hard part: unfortunately, you can t bind a multi-value report parameter to a dataset parameter (at least, not in version 3.2, which is what I m using). There s a posting on the BIRT World blog here:
http://birtworld.blogspot.com/2009/03/birt-multi-select-statements.html
that describes how to use a code plug-in to bind multi-select report parameters to a report dataset.
prepare(this);
function prepare(dataSet) {
while (dataSet.queryText.indexOf("@IN?")>=0) {
dataSet.queryText = dataSet.queryText.replace(
"@XYZ?",
"( "+params["products"].value.join(" , ")+" ) or ?=0"
);
}
}
In your query, replace occurrences of (?) with @XYZ?. The method above makes sure that
the query has the actual values and still a parameter (so that the dataset editor and preview doesn t complain).
/** Fullfill IN-clause in a data set query,
* using a List box report parameter.
* Placeholder must be the parentheses after IN keyword with wathever you want inside.
* If required is false then the whole IN-clause in the query
* must be surrounded by parentheses.
* dataType and required refers to the parameter, they must be passed,
* but should be better to find a way to retrieve them inside this function
* (given parameter name).
*/
function fulfillInClause(dataSet, placeholder, param, dataType, required) {
if (dataSet.queryText.indexOf(placeholder)>=0) {
var paramValue = params[param].value;
var emptyParam = (paramValue==null || paramValue.length<=0);
//build the list of possible values
// paramValue==null check in ternary operators
// will prevent exceptions when user doesn t select any value
// (it will not affect the query if param is optional,
// while we will never arrive here if it is required)
var replacement = " (";
if (dataType == "string")
replacement += (emptyParam ? " " : createList(paramValue, ",", " ", "varchar(10)") );
else if (dataType == "integer")
replacement += (emptyParam ? "0" : createList(paramValue, ",", "" , "int" ) );
else
//TODO implement more cases
return;
replacement += ") ";
//if param is not required and user doesn t select any value for it
//then nullify the IN clause with an always-true clause
if (!required && emptyParam)
replacement += " or 0=0 ";
//put replacement in the query
dataSet.queryText = dataSet.queryText.replace( placeholder, replacement );
//DEBUG
params["debug" + dataSet.name + "Query"]=dataSet.queryText;
}
}
/** Create a string list of array values,
* separated by separator and each of them surrounded by a pair surrounders
*/
function createList(array, separator, surrounder, sqlDataType){
var result = "";
for(var i=0; i<array.length; i++) {
if(result.length>0)
result += separator;
if(array[i]!=null)
result += surrounder + array[i] + surrounder;
else
result += "cast(null as " + sqlDataType + ")";
}
return result;
}
Usage example
在数据查询中,请你特别说明:
select F1, F2
from T1
where F3= Bubi
and ( F4 in ( /*?customers*/) )
I am building a simple BIRT report using an XML data source. However, I had to use 3 different views (3 cross-tabs) of the same data on the same report. While running the report, I noticed that BIRT ...
I have one dataset and create from this set an area chart. In this case no problem.
But now I have the requirement to add dynamic markers to the chart.
So, this is the example:
Data Set:
date | ...
so I am having pretty much exactly the same problem as what someone else has described here:
birt-exchange.
I have integrated BIRT with my existing web application that requires the xerces jar (mine ...
User table contains the following attributes (dateOfBirth, race, gender, ...). We would like to generate a report in the following format.
Year Race All Male Female
2000 Asian 2000 1000 1000
...
I m designing an accounting report with various aggregations and data fields and when I try to aggregate on a field I get the following error:
"Target Aggregation Name does not exist"
Now... the ...
How to make a linear regression on the chart displayed into your BIRT report.
I have x and y data... but I don t see any function on eclipse BIRT to generate the linear regression...
Any idea ?
Many ...