Pass dataset to subreport with SQL Server Reporting Services - reporting-services

I'm using SQL Server Reporting Services and the report designer that comes with Visual Studio. I've got a really big report. It's actually so large that Visual Studio hangs (sometimes for hours at a time) or just crashes when I make changes.
There is preciously little I can do to solve the problem, so I've decided to just move the bottom half of the report into a sub-report. So, I started with one enormous, unresponsive report and ended with two small, manageable reports -- surprisingly, this actually works.
One problem: my subreport uses the same data as my main report. Right now, it populates its dataset by re-querying the database. The extra round-trip to the database causes the report to take twice as long to generate; up from 45 minutes to 1 1/2 hours to generate.
I'd like to avoid hitting the database again, and instead use the same dataset in both reports.
How can I share or pass a dataset between a report and subreport?

I think this can help you:
http://www.gotreportviewer.com/subreports/index.html
Supplying data for the subreport - the SubreportProcessing event To
supply data for the subreport you have to handle the
SubreportProcessing event. Note that this event is on the LocalReport
object. You can add an event handler like this:
private void MainForm_Load(object sender, EventArgs e)
{
this.reportViewer1.LocalReport.SubreportProcessing += new SubreportProcessingEventHandler(MySubreportEventHandler);
}
Below is an example for the event handler. In this example
LoadSalesData is defined to return a DataTable.
void MySubreportEventHandler(object sender, SubreportProcessingEventArgs e)
{
e.DataSources.Add(new ReportDataSource("Sales", LoadSalesData()));
}
If your report has multiple subreports you can look at the ReportPath
property of SubreportProcessingEventArgs and supply data for the
corresponding subreport. You may also want to examine the values of
Parameters property of SubreportProcessingEventArgs and only return
the subset of data that corresponds to the subreport parameters, as
mentioned here.

I'm pretty sure you can't. You're probably better off looking for ways to redesign the report entirely so that it's not so large... not to mention the various problems with subreports when exporting to excel.

I have several reports that the SQL is so complex in that it locks up Visual Studio when I try to edit it. In these reports I go straight into the Code view and edit the XML directly, which works. I also do this when Visual Studio mysteriously makes columns slightly wider than I set them at. However, I doubt you'd want to go down this path if you are editing the layout of the report too much.
Instead of running your query in the report, would it be possible to build a table using a stored procedure that both reports use? The first report runs the stored procedure to build the table and then both reports simply query the report. Watch for concurrency problems if the report can be run by multiple users.

Have you tried using a list within a list where both lists use the same dataset and then filter the inner list to display only records linked to the the outer list?
As far as the execution time, 45 minutes seems like an awful long time in the first place. I'm assuming you've done some analysis of the execution plan to verify your query or stored procedure is using meaningful indexes?
Hope this helps,
Bill

You can do it using a dummy parameter:
i. Create a parameter in your main report 'MyData' and tick 'internal'
ii. Set default value of 'MyData' to your data-set
iii. Set the sub-report parameter with the expression
=Parameters!MyData.Value
Hope this helps,
Duncan

If you create a table, you can merge all the cells of the details row and put a subreport as the contents. Then set the parameter of the subreport to the field you want to run the subreport against.
Jason

Related

How to pass a record from ssrs main report dataset to subreport

I have a customer dataset from a main report which I bind to a list. In this list I have a subreport. How do I pass the each row of data to the subreport? I don't want to pass an id from main report to subreport then call a stored procedure to fetch the record based on the id. I already have all the details flattened out in the dataset which i fetched from the main report.
The fact is that you can't pass a set of rows as a parameter to a subreport. The most common approach is to have a shared dataset so you can execute it again based on the same parameters or a store procedure for exactly the same purpose. Only other thing can be done, and it's to convert a dataset's field into a string containing all the values, and then split it again. This is done with SSRS built-in functions join and split (if I'm not wrong), but to be honest I don't know if that solves your problem and it's a really nightmare to get it working properly.
My standard approach is to have efficient stored procedures that can be executed any times within a set of SSRS reports. I understand that you want to retrieve each datataset only once, but SSRS is not meant to make that easy.
And even more important, if you queries or procedures are efficient, data retrieval time is just a tiny porting of all SSRS report build and presentation time. Usually rendering the report is what takes longer and some repeated data extraction won't be noticed in the overall execution.
If you what to be really efficient in data retrieving, you can explore the options provided to cache data in datasets, but stills seems to be too complex to solve something that doesn't really need a solution.
Hope this helps.

Get data from a subreport into the main report

I have made one main report containing a few subreports. At the end I would like to compare some figures from the different parts of the report and also make some calculations with numbers received from the different parts.
Does anybody know a way to get values from the subreport into the main report? All calculations e.g. aggregates that will be made at the end refer only to the dataset for the main part and the other subreports have their own datasets, fetched from other tables.
I must second #JoaoLeal's comment, I think the method you propose (retrieving data from a subreport in the main report) is technically not possible.
However, there's another way to achieve what you want (show aggregate info on the data displayed in subreports). You could encapsulate your dataset queries in a way that they can be reused by the main report. There are two main/basic options:
Use a stored procedure to query the data
Use a database view for the data
Your datasets will be very simple: the subreports will select all the data. The main report can then either have a dataset query that aggregates data appropriately from the view / proc, or also retrieve all results and do the aggregation in SSRS.
I think in RDLC report there is no way for share variable between main report and subreport . So the only way is use another dataset or passing new vaiable. Hope this will help...
I have myself managed to achieve what I expected through using different datasets on the main form which also contains data for the sub reports.
But also I found this way (not tested):
[Reports]![YourReportName]![YourSubReportName]![TheValueFromTheSubReportYouWantToReference]
There is also a long discution about this on SQL Server Central.

MS reporting services limiting number of rows

I have a report working well where I extract the number of logins per user. Each login takes up one row on the report.
I have date parameters and my DB goes back a year. However it seems the report will only show 40/50 rows despite a report expecting to deliver, say, 250 for the amount of times I logged in.
Is there some setting in reporting services that limits the number of rows delivered. Can't find it anywhere..
Thanks.
The answer to your question: nope, as far as I know there's no real equivalent of SQL's TOP 50 statement in SSRS itself.
Some things that come to mind that may be causing your symptoms / can be investigated:
What happens if you run the query for the dataset in SSMS? Be sure to fill in the exact parameters the report's using (if any).
Run the query as a test from SSRS designer. If you're using Visual Studio: right-click the dataset and hit "Query...", then hit the red exclamation mark and fill in any parameters if needed.
Try putting a CountDistinct call (on your dataset) in a textbox somehwere in the report, by itself.
Check the filtering and grouping on your tablixes, perhaps even by looking at the XML source code for the RDL.
Show the parameters in textboxes (oldskool printf debugging! :D) to make sure they're what you expect them to be when the report's run on the Report Server. If they're not: try deleting the report on the server and re-deploying it.
Have a look at the ExecutionLog2 View in the ReportServer database, specifically the Number of Rows returned.
As mentioned in the comments by Atilla: You may also monitor exact SQL SSRS sends to server using SQL Server Profiler.

Report structure from table

I have a large project with a lot of reports, but the items in the reports are quite standard, reusable with parameters. So I've made subreports, that's OK. Now I assemble the reports by adding subreports to them by hand, plus setting the parameters, also by hand.
I think that this is not flexible enough, I'd like to have a table that defines the structure of the report: like one row per subreport, specifying the name and its parameter values. Then the report would be assembled together runtime in a list or something like that, by calling and inserting the subreport by name.
Is it possible somehow?
I can't think of a way to dynamically assemble a report like that without coding something that would generate the required RDL, upload it to the report server and then execute the report.
Another option might be to create one master report with all possible subreports in it. You could then use a table to control the visibility of each subreport, to simulate generating different reports. Obviously you don't want to execute long running queries for subreports that are hidden, so you would have to add a parameter to all your subreports so that if the subreport is hidden the dataset returns no data, e.g.
WHERE
(....) OR (#SubReportHidden = 'Hidden' AND 1=0)

SSRS -> Using code function to create my query dynamically, how do I get at my data (put data into table)?

I am not a seasoned SSRS veteran. I have made quite a few but they were pretty simple.
Today, I am attempting to use the Code tab of the Report Properties to perform some vb functions that will return my query in a string. I am passing in date parameter that is used to create my dynamic query.
My problem/issue is that I do not know how to pull this information into my table.
I have seen instances where a developer calls from each individual field and it calls the code to get a specific field. I was under the impression that I could somehow use a dataset to do this and have some documentation on this, but can't seem to find anything on the web regarding how to do this.
This is probably a pretty poorly written question, but does anyone know how to do this?
I was thinking in the Dataset Properties, I would code something like this in the expression field.
=Code.GetReportDetail(Parameter!InputDate.Value)
GetReportDetail being the starting function within my code window.
I am having difficulties how I can then pull that dataset into my table from that point though.
Any advice on this is greatly appreciated....Thanks.
After further review, I was creating this in VS2010 for RC0 2012 SQL Server, which I should have noted above.
All you have to do is create your report by adding new item (Report). Add your code by right clicking in the pink area and going to Report Properties and pasting your code into the code tab.
Next when you pull a table into your "add item to the report / white space" It allows you to create your dataset.
I chose use dataset embedded in my report. Datasource of OLE DB because I am doing MDX. Query Type Text then in the function I pasted this. (omitting parameters for now) :
=Code.GetReportDetail()
I then filled in fields manually because it seems that dynamic query running does not pull in fields.
I was then able to reference these manually created fields via my table detail row.