Dynamic selection of dataset in SSRS - sql-server

I am going to design a report using SSRS 2005. Is it possible to have the selection of dataset done dynamically?
Let's say I am going to have two tables, where the first one is the summary and the second is the detail data. One of my parameters (with values Summary and Detail) will determine which version of the report is to be displayed. Can I have two different datasets, and while clicking the view report button in parameter view dialog (or before) set which dataset which will be used?

You can use the single data set by using switch statement some thing like this:
You can type this in data tab but the results can be seen only in preview tab, but not the data tab like regular queries.
=Switch(Parameters!ToDecide.Value = "Summary",
"Your query for Summary",
Parameters!ToDecide.Value = "Detail",
"Your query for Detail")
Make sure you don't have any excess spaces with in the query(not more than one space where needed)
Both the queries should return the values required by the Table in Layout.

You'll probably have to have 2 pairs of table contained in, say, a rectangle, and hide the unused one (at the container level). Or use subreports.
If you find a way to switch datasets, then you'll have to make sure that all columns are the same as well as making sure that any functions using the DataSet as a scope parameter are changed too... which makes me think it just isn't supported.

You might want to try using a single dataset and having a summary and detail data region (table, list, etc.) in the report, one of which is visible and one of which is not. In this scenario, the dataset is only evaluated once and you are still meet your requirement.
Hope this helps,
Bill

It would be easier to create and maintain if you have two separate tables and hide one or the other depending on the choice made.
I haven't tried this, but I think another possibility would be to use three reports: a container, a summary subreport, and a detail subreport. Switch between the subreports according to the choice.
There is a performance gotcha to the first implementation though. SSRS will try to fill every DataSet in the report when it loads, even ones that are not used in the report's output or by other DataSets or expressions. In other words, just because you're displaying the summary report, doesn't mean that you're not asking the database to fill out your detail data as well.
There is a workaround that can improve the performance a bit, but will still end up with a trip to the server. The hack is to set a flag parameter to determine whether or not the query should actually return any real results or if it should just return the columns you want.

You may try adding condition that depends on a cetain parameter to execute. Then from there, You may use different data set. Assuming that you'll use it on separate hidden tablix.

Related

SSRS Dynamic Reports for Key Value Pairs

I need to use SSRS to create many different reports, and I have been trying to find the best way for me to easily create them as need, and for users to navigate them and use them for their needs.
To give you and idea of the two sets of data I am dealing with:
EDI file from our customer
Raw data output from hardware configuration
Now the EDI data is fairly consistent, so these columns are static.
The hardware data is usually a massive list of different configuration. I receive them in different flat files formats and using SSIS or other tools I get the data into Key Value Pairs. Now in a report, I use matrix to keep EDI columns static, it matches with the hardware on serial number, and Hardware data pivots.
So the report does not break, and so I don't give the user too much information, it matches up on another table where I specify what keys I want to be columns.
Here is a small example of one of my reports:
The green columns are EDI, while the orange is the hardware.
My question is, is there a better way for me to be doing this? Some reports can get complicated like needing total for certain hardware (counting hardrive space, ram total etc.) which is difficult to do dynamically.
I have tried creating in reports in this fashion, with these parameters:
This way I can create the Key columns per project and user can select what report they want to run. The default is All Data.
Is there a better way for me to create these reports? SSRS really doesn't seem to play well with dynamic pivots.
Is there a better tool that will handle these reports dynamically, or let users pick and choose what they want to see in a report?
I can't visualise your data but if I understand correctly, you could have a dropdown list showing all the unique values that are in the column you are using in the column group. Set this to be multi-value and then simply have the WHERE clause read something like
SELECT * FROM myTable WHERE myColumnGroupField IN (#myColumnChoiceParameter)
This way the user could select whichever columns they would like.
You could extend this by adding another parameter that has some preset groups of columns (I think you might have one of these already if I understand correctly) that would set the default value of the main #myColumnChoiceParameter parameter.
If you want something more flexible then you might want to look at Power BI but depending on how you intend to deploy that might not be a simple option.
You cannot dynamically create columns in SSRS but you can control the visibility of the columns.
1) Create a list in table that contains the names of all the columns that yo want to toggle and include a column titled 'All'.
2) Create a parameter that is based on this table and make sure multi-select is turned on.
3) Right click on every column that you want to toggle, select visibility and then create a condition that checks if the user either selected All or selected the column from the parameter list.
4) Train users that by selecting and deselecting from the dropdown they control whats visible.

SSRS Error - "Report item expressions can only refer to fields within the current dataset scope or, if inside an aggregate

I'm new to SSRS and I'm not sure if it will do what I would like to do.
I'm getting the following error in SSRS:
"The Value expression for the text box 'Textbox17' refers to the field 'DayCnt'. Report item expressions can only refer to fields withing the current dataset scope or, if inside an aggregate, the specified dataset scope. Letters in the names of fields must use the correct case."
I have a list that's 3 rows and 3 columns. I need to use multiple data sets across the rows and columns. I would like everything on the report to be grouped on the school ID, which each dataset does have.
I will be using multiple datasets per cell in some cases and I'm using a textbox and then dragging the dataset field into it. I'm not sure if grouping is the problem. I'm not sure how to group the entire list at once, or if it is row based, or how the grouping works with a list with multiple columns.
How can I get everything in the list to be based off of the school ID?
You can reference more than one dataset in the same data region (table, etc.) but only if it makes sense to use aggregate functions on all the datasets except the primary one that your grouping is based on. I'm not sure if this makes sense for your use case or not.
An aggregate function is something like First. If you don't specify the dataset, it defaults to the "current dataset." The current dataset is an invisible default that you can't see or set anywhere in the UI, as far as I can tell.
=First(Fields!MyField.Value)
vs.
=First(Fields!MyField.Value, "MyDataset")
Now, there are a couple of tricky things to know about the Report Builder UI.
When you drag a field into your report, the expression it creates does not specify the dataset.
When you drag a field into your report, it changes the current dataset!
This leads to exasperating behavior such as the following:
Create a data region.
Set its grouping to a field from Dataset1.
Drag in a field from Dataset1.
Run the report. It works!
Drag in a field from Dataset2. RB will automatically use an aggregate function, as you would expect.
Run the report again. Now you get an error, not on either of your fields, but on the grouping of your data region.
The problem is that dragging in the field from Dataset2 changed the current dataset to Dataset2 and broke everything that uses Dataset1 without explicitly specifying it. The solution is hacky:
Manually change the expressions of all your fields from Dataset2 so they explicitly reference the dataset, or
Reset the current dataset by dragging in a field from Dataset1 and deleting it.
You cannot use different datasets on only one SSRS table. One table should only refer to one dataset.
And the solution to your question is: recreate your dataset (query), try to get one dataset by using distributed query if they are on different server instance, or specify database name when they are on the same server.
You might have done some modification on the Dataset and you did not refreshed the fields.

BIRT Dynamic Columns

What I am currently looking to do is use our existing UI to select a number of columns from various tables (yes, multiple tables) and pass them into a BIRT report as parameters. From there, I am planning on building a query that will dynamically replace the columns into the query and pull the results automatically. I'll have to hide columns with no value passed to them as well. I also expect I'll have to setup the query to be a little heavy handed and already know all of the logical connections in the database (e.g. connect the proper tables, etc).
My question is this the best way to manage a dynamic column/table in a dataset? or is there a better way to manage this method? I'v seen some online information about the "ad-hoc" BIRT report designer that lets non-programmers create reports, but I am not looking for other people to actually build the report, just generate one using an existing template with interchangeable columns.
I think the easiest way is to firstly build a report with all columns that you need.
Then apply some logic on the visibility of the column. You can use the parameters there as well.
Select your table, select a column, open the properties window and take a look at the visibility tab there. Just add some logic that results in a true or false.
If you are using a crosstab to display the information, you could use the filter options to include or exclude columns.
Yes, this will load data that is not used, but you need to build realy big reports for performance becomming a real issue.
If you try to add this logic in the actual dataset, you have to make the query and fetch script dynamic and then you still have the problem with the visualisation of the columns. I think you'll end up using the visibility script anyway (to show/hide the colums on the report), so might just start from there and have a working report fast.

How to display results from Stored Procedure WinForms

I have a stored procedure in SQL Server that returns different structures based on the parameters.
In other words, it might return a result set with three fields, or 15, and the column names are going to be different.
How can I display these results in a WinForm app?
I currently use the Entity Framework for accessing data, but obviously that is not going to work in this situation.
The data will be readonly, ie, no need to edit. Just need to display it.
I am guessing that I need to skip EF and just call the SP directly, and populate a DataGridView with autocolumns.
Greg
Since you're retrieving a dynamic data structure you'll need to make your grid columns dynamic too. What I would do is, after retrieving the result set successfully, to clear the Columns collection and recreate them from scratch every time you called the SP and the data needs to be refreshed on-screen. Do not use AutoGenerateColumns, as they provide little chance to customize the look of them, instead define each and every column yourself so that you can choose what to display and how.
This is the best answer I found: How to use a DataAdapter with stored procedure and parameter
In short, use a DataAdapter and a DataTable. Even with AutoGenerateColumns, the column headers look great and it works no matter the table structure that comes back.
Greg

Hide row of data in matrix by field value

I need to know how to code this. I am working with program numbers and there is one that I do not want to be displayed. I am trying:
=Fields!NoProg.Value="08007"
But then I do not know how to tell it:
(pseudocode)
if NoProg = 08007, then do not display.
As I see it, you have two options:
Filter out the row you don't want in your resulting dataset at the database side. This has the advantage of using indexes if you have them set up. This involves putting a WHERE clause into your query. If you cannot change the query or need the row to be in the resulting dataset but simply hidden, choose this option.
SELECT ...
FROM ...
WHERE NoProg <> '08007'
Hide the row in the report, as you are already doing. This has the advantage of keeping the data in the resulting dataset but hiding it from that section of the report. If you are performing aggregation and need to include the row elsewhere but just hide the detail from view, choose this option. Keep in mind, this will not use any database indexes, so it requires one comparison for every row in the resulting dataset.
<Hidden>=Fields!NoProg.Value="08007"</Hidden>

Resources