Reputation: 3028
I created one birt report.It contains one report parameter with name "FromDate".User will insert it in a fromat like "dd/MM/yyyy". I want to get year(if date is 11/01/2013.i want to extract 2013 from this varaible) from this input parameter and want to pass this value to one stored procedure(ie data set).How can i do that.Can anyone pls share sample code
Upvotes: 0
Views: 2545
Reputation: 13
In sql query(Data Set), Use this
"split_part(?,'/',3)" , We will have date parameter in place of '?' . As, you must be aware of that, Split_part will divide the string using the delimiter '/' .
Upvotes: 0
Reputation: 3028
i tried this one..in corresponding stored procedure i will do a substring on input paramaeter(ie FromDate)..it is working
Upvotes: 0
Reputation: 11
I had a similar problem in the past, however i looked at from a different angle in driving the date selection from the dates stored in the datasource as a dynamic parameter. Normally then a date from the dataset is in a format which can be formatted/extracted by functions to give the year month day etc.
Upvotes: 1
Reputation:
You can map dataset parameters to report parameter-derived values in the Parameters section of the Edit Dataset dialog:
Edit...
.fx
button next to the Default Value and select Javascript Syntax
.BirtDateTime.year(params["FromDate"].value)
.Click on OK to confirm these changes in each dialog. (The Linked To Report Parameter option needs to be left as None
for that dataset parameter, since you don't want to set the procedure input parameter value to be exactly the same as any of the Report Parameters.)
Upvotes: 1
Reputation: 313
You could define a variable 'selectedYear' like this:
var selectedValue = params["FromDate"].value;
var selectedValueArray = selectedValue.split("/");
selectedValueArray[2]
This code creates an array by "cutting up" the parameter value on the /'s, and then selecting the year (the second value in the array, which is the third block since we count from zero).
You can then use vars["selectedYear"]
on your data set.
Alternatively, if your data set contains a list of years, you can create a data set
select distinct YEAR
from [dataSource]
and have your parameter select from that list instead. This will also guarantee that the selected year is in range.
Upvotes: 1