Reference a Main_Dataset in a subDataset - jasper-reports

I want to reference my MAIN dataset in a Jasper .jrxml when querying for my subdatasets.
I have about a dozen sub-datasets that all rely on the main set, in the following way:
SELECT
what_i_need,
for_my,
subdataset
FROM
(my main dataset which has a fairly long query) m
group by m.sth
order by 3,4 desc, 2;
What that does is query the main and then use that as a table to query for the subs, but the drawback is that I have to change every subdataset manually every time I need to change the main
I'm aware that I COULD go for creating a view in the database and then simply referencing that from inside Jasper for both main and subs.
(And also changing the view definition as needed)
I'm asking whether Jasper can be "taught" how to use the entire main dataset as a parameter for the subdatasets?
The goal is to set all the subdatasets once with some sort of parameter, and only change the main, and have the expected results.
The end goal should be something like this:
SELECT
what_i_need,
for_my,
subdataset
FROM
$P{Main_Dataset} m
group by m.sth
order by 3,4 desc, 2;

Add String parameter to your dataset, let's say pQuery.
SELECT ...
FROM ( $P!{pQuery} ) m
GROUP BY ...
ORDER BY ...
Exclamation ! char is important.
In chart's datasource:
Use connection expression with default value $P{REPORT_CONNECTION}.
Add pQuery parameter and set expression as $P{JASPER_REPORT}.getQuery().getText()

Related

ADF Copy function comparing watermark against isnull(date1,date2)

Forum Newbie...
I want to utilise the ADF Copy function, to carry out incremental table extracts from one Azure DB to another. Every table in the database that I need all have the same 2 relevant fields i.e. date1, date2. For Watermark comparison purposes, I need to use isnull(date1,date2), but unsure how to do this, i.e. I am not sure how I can add this consistent derived value to the Source as an additional field that can perhaps be added via the Query or Stored Procedure Option on the source, to utilise the #item().source.schema and #item().source.table values that have already been generated as parameters..?
You can use the query option in the Copy data activity source and add a new column in the query itself to get the results of isnull(date1,date2) and include the parameter values to get the table name instead of hardcoding them as shown below.
In source, select Query option under Use query and add dynamic content to concat() select statement with parameter values.
#concat('select *, isnull(date1,date2) as final_dt from ',pipeline().parameters.schema,'.',pipeline().parameters.table)
Sink table data output:

Use value returned from main dataset in sub dataset of iReport

I have created a report with Jaspersoft Studio 6.4.3.final which contains List Element. I need to use value returned from main dataset in sub dataset (List Element) query.
Main data set return something like below. (always only one record return)
CustomerName JobID
John 123,146
I need to use JobID in sub dataset (List Element) query as below.
Select * from JOB where jobId in (123,146)
I need to use the 123,146 form value returned from main dataset.
How could I achieve this?
What I have tried
I have created a parameter in sub report as below.
Then bound the relevant field from main report to the sub report parameter as below.
Updated the sub dataset query as
Select * from JOB where $X{IN,jobId,p_jobId}
With these changes, I am getting below exception.
Invalid type java.lang.String for parameter p_jobId used in an IN
clause; the value must be an array or a collection.
You can pass the value returned from the main dataset as a parameter to the List element and use it in the subdataset.
If it's a multi value parameter, you can use the $X notation in the subdataset query.
So your query could look something like this:
Select * from JOB where $X{IN, jobId, MyParam}
Where MyParam is the subdataset parameter name.

SSRS multi value parameter - can't get it to work

First off this is my first attempt at a multi select. I've done a lot of searching but I can't find the answer that works for me.
I have a postgresql query which has bg.revision_key in (_revision_key) which holds the parameter. A side note, we've named all our parameters in the queries with the underscore and they all work, they are single select in SSRS.
In my SSRS report I have a parameter called Revision Key Segment which is the multi select parameter. I've ticked Allow multi value and in Available Values I have value field pointing to revision_key in the dataset.
In my dataset parameter options I have Parameter Value [#revision_key]
In my shared dataset I also have my parameter set to Allow multi value.
For some reason I can't seem to get the multi select to work so I must be missing something somewhere but I've ran out of ideas.
Unlike with SQL Server, when you connect to a database using an ODBC connection, the parameter support is different. You cannot use named parameters and instead have to use the ? syntax.
In order to accommodate multiple values you can concatenate them into a single string and use a like statement to search them. However, this is inefficient. Another approach is to use a function to split the values into an in-line table.
In PostgreSQL you can use an expression like this:
inner join (select CAST(regexp_split_to_table(?, ',') AS int) as filter) as my on my.filter = key_column
Then in the dataset properties, under the parameters tab, use an expression like this to concatenate the values:
=Join(Parameters!Keys.Value, ",")
In other words, the report is concatenating the values into a comma-separated list. The database is splitting them into a table of integers then inner joining on the values.

Unable to dynamically change value for static label column header

I am unable to dynamically change the column header values during run time while creating a jasper report. Why do I keep getting string to boolean cast exception everytime I assign the value to table element's column header??
I have a column header that is a part of the table element. And this table and its dataset are not a part of the main data set. I want to the column header to change dynamically based on values in the main dataset. The main dataset and sub data set return different resultsets
The steps I followed were:
create a variable called v1_enabed (string) and v1_display(string) in the main dataset. I also assigned the required fields(from the main data set) to these variables
I created a parameter p1(string) in subdataset
I use the subdataset fields for table creation. I used the table element.
I go the table and map the parameter p1(string) to the table. And I assign the expression ($V{v1_enabled} == Character.toString('1')) ? $V{v1_display} : $V{v1_display} to it
Until here whenever I run the report, I do not get any error.
Now, I go the table. Pick up the 5th column and assign this in the print when expression section -- $P(p1)
Now, comes the error: java.lang.String cannot be cast to java.lang.Boolean
How do I solve this?

SSRS: Call a dataset from a textbox with a parameter

I have a dataset that is a query which has a where clause like this 'where field1 like #parameter1' parameter1 is a string defined as a parameter in the dataset1. I have various text boxes that calls the dataset with expressions like =First(Fields!field_xx, "Dataset1"). For each textbox I like to specify a different value for #parameter1 when it calls the "dataset1". How can I modify the expression in each textbox as to call the "dataset1" from each of them with a hardcoded value for #parameter1
the query:
SELECT TOP (1) job.job_id, job.originating_server, job.name, job.enabled, job.description, job.start_step_id, job.category_id, job.owner_sid, job.notify_level_eventlog,
job.notify_level_email, job.notify_level_netsend, job.notify_level_page, job.notify_email_operator_id, job.notify_netsend_operator_id, job.notify_page_operator_id,
job.delete_level, job.date_created, job.date_modified, job.version_number, job.originating_server_id, job.master_server, activity.session_id, activity.job_id AS Expr1,
activity.run_requested_date, activity.run_requested_source, activity.queued_date, activity.start_execution_date, activity.last_executed_step_id,
activity.last_executed_step_date, activity.stop_execution_date, activity.job_history_id, activity.next_scheduled_run_date, steps.step_name
FROM sysjobs_view AS job INNER JOIN
sysjobactivity AS activity ON job.job_id = activity.job_id INNER JOIN
sysjobsteps AS steps ON activity.last_executed_step_id = steps.step_id AND activity.job_id = steps.job_id
WHERE (job.name LIKE 'Actual Job Name')
ORDER BY activity.start_execution_date DESC
It is not possible to call a dataset with different parameters in the same report execution. Every execution and rendering of the report fetches each dataset only once.
This means that you have to construct your dataset in a way so that it returns all the data you need, to populate each of your textboxes.
Depending on your data model, you may want to add more columns to your dataset, or return the data in multiple rows. If you have multiple rows, then you can use the Lookup function in an expression, to filter out the row in each individual textbox.
Perhaps if you elaborated a little more on what your report should look like, and what the structure of the data you are fetching is, it would be possible to give a better answer to how to solve your problem with a single dataset.