SSRS passing parameter to subreport - sql-server-2008

I have 2 tables which both have the column "countyID"
I have a main report that brings up reports based on a query like:
SELECT countyID, name, address, state
FROM TableA
---I have a parameter set on TableA where you select the Name to view its report.
I then have a second report based on a query like:
SELECT *
FROM TableB
I want to use the second report as a subreport, as in, when you select the Name for the top report it should then list all records from TableB with the same CountyID.
Is there a way to set countyID as a parameter and then pass it to the subreport? This way the subreport would always only return records with matching countyID's to the currently selected record of the main report.

I'm assuming that you've created a drop-down #Name parameter to load into the DataSet you're using for TableA. You've configured this Parameter to specify its values from the Name field of your TableA DataSet, which likely uses a query similar to:
SELECT CountyID, Name, Address, State
FROM TableA
WHERE Name = #Name
You would then need to create another parameter to store the relevant CountyID values from that DataSet, e.g. #CountyID. Set it to 'Hidden'. For the Available Values and Default Values, point it to the same TableA DataSet, but have it use the CountyID field for its values/labels.
You'd then need to pass the #CountyID parameter into your subreport. The DataSet for this tablix should be, like you outlined:
SELECT *
FROM TableB
WHERE CountyID = #CountyID
Are you sure you're using a subreport for this, and not just another tablix? The reason being, if you are using a subreport, you would need to open the subreport report object and create the #CountyID parameter on there as well, assuming that is where the TableB DataSet is. Set it to Hidden but don't worry about setting any values, since it will received from your Main report.
Lastly, go back to the original Main report, right-click on the subreport box that you dragged onto your report body, and go to Properties > Parameters > Set Name to CountyID , and the Value as [#CountyID] .
**Note: In SSRS, parameters have the annoying trait of being case-sensitive. It's always good to keep this in mind sooner rather than later in report development.

Related

Populate a parameter dropdown based off another parameter

I am trying to populate a dropdown based off another dropdown parameter. I have 5 parameters, but the first 3 populate the 4th in the report. So the 4th and 5th parameter are what the user uses to populate a report. So the 4th parameter (meetings) has a meetings dataset and the 5th parameter is meetingType with a dataset of meetingType. So when the user selects a meeting, then the meetingType gets populated by that selection. Currently both dropdowns produce all results, which I don't want. I just want all results for meetings and then the meetingType gets populated by meeting.
The table it produces once the report is ran doesn't use those properties and there isn't a place to query anything. I can only use available values from each dataset and not use available values based on the selection of the 4th parameter.
I'm not really clear. do you need a parameter or do you just want to have the meeting type available as a value in your report output?
Fairly straightforward. You have two datasets, one for each parameter. You need to filter the second dataset based on the first parameter.
For example, I often create reports that ask for a range of values, let's say programs. Once the user has entered the beginning value, the ending value must be greater than or equal to the beginning value. So, on the ending value dataset I create a filter. In this case, the filter says that the field code (which is my program) must be between the starting parameter and the maximum value allowed:
You can make your filter as complex as needed - referring to the other parameter with a formula
You can also do this via separate datasets for each parameter.
Lets say you have two parameters #param1 and #param2
you want the values on #param2 to change based on #param1 selection.
You will have your main dataset (main_dataset) with a where clause something like this
where sometable.somecolumn = #param1
and sometable.someothercolumn = #param2
Now you create a dataset (param1_dataset) for #param1 which brings back all the values you require for this parameter
Now create another dataset (param2_dataset) form #param2 and add a where clause to it which restricts the returned list.. something like this..
where sometable.somecolumn = #param1
Now on your report parameters.. set the Available Values for each parameter (report parameter properties) to "Get Values from a query" and select the appropriate dataset and the value field and label field (returned by the dataset) for each parameter.
Now when you run your report, your parameter selection 2 should change based on what you selected for parameter selection 1

Accessing one Dataset in Another Dataset (SSRS)

There are 2 Tables on Two Different Servers,
I Have Dataset1 pointing to Server1.
Similarly I have Dataset2 Pointing to Server2.
Now I want to Use some Values from Dataset1 in Dataset2.
Dataset1:-
Select * from Table1
This has Name,Lessthan,GreaterThan
Dataset2:-
Select * from TableX X inner join Dataset1 on Dataset1.name=TableX.name
Where X.Time>Dataset1.Lessthan and X.Time>Dataset1.GreaterThan
Have tried doing the same as above but we are not able to Access the contents of Dataset1 in Dataset2
It Throws error As 'Invalid Object :-Dataset1'
Please guide me on this.
You're right: a Dataset's query can't access another Dataset: the query is sent to the database server, which knows nothing of your other Dataset which is defined in the report only.
You can make some report parameters (which can be hidden from the user), which use your Dataset 1 to provide their values.
Then you can pass the parameter values to Dataset 2: when you open Dataset 2's properties you will see 'Parameters' on the left. In Dataset 2's query, include things like #paramvalue, and you will be able to supply it with your values from your report parameters.

Depending Parameters in a text box (SSRS 2008-R2)

I am working on a SSRS Report and I have two Parameters in the Prompt section, EmployeeID and EmployeeName respectively.
EmployeeName prompt depends on the EmployeeID prompt selected, can the EmployeeName be populated in a textbox once EmployeeID is selected.
Right now EmployeeID is being shown in a drop-down and the user have to go to the drop-down and select it, can it be done in a textbox?
Any help would be greatly appreciated!
Create your main report dataset (dsMain for exmaple) with a query something like
SELECT * FROM myTable WHERE EmployeeID = #EmployeeID
I'm assuming you have the first parameter setup and working correctly to return your list EmployeeIDs. For this example we'll call this parameter EmployeeID/
Create another dataset (called for example, dsEmployeeName) with a query something like
SELECT EmployeeName from myEmployeeTable WHERE EmployeeID = #EmployeeID
In the second parameter (the one you want showing in a text box), leave the 'Available Values' blank and set the 'Default Values' to be from a query. Choose dsEmployeeName as the dataset and choose EmployeeName as the Value.
NOTE This will only work the first time round. If you choose another value from the drop down, the name will not be updated.
I don't know your exact requirements but if you can get both the ID and name together, why do you need two parameters, one of which does nothing really as it's not passed to the report?

Sending multiple values in ssrs parameter to subreport

Currently have three subreports, one main report.
Main report has two parameters - SELECTDATE and EMP_ID. Main report sends Order_Nbr to all subreports.
All subreports work perfectly when I only select 1 Employee and 1 date, but if I choose multiple values it blows up.
SQL has the column as an INT. I have both parameters in main report and subreport, SELECTDATE is set as Text with Multiple Values, and EMP_ID is set to Integer with Multiple Values. My queries has my date IN (#SELECTDATE) and emp_id IN (#EMP_ID).
It obviously sends the correct information to the subreports because it works, but I would like it to work with more values being passed. Love the current ability to check and uncheck employees and end of month dates, like it currently is set using the IN function in my query.
Make the Parameters on your sub report non-multivalue, remove any 'Available values' set.
Pass the multivalue parameter from you parent report as a string using the join method
=Join(Parameters!Emp_ID,",")
The EMP_ID parameter will be set to a comma delimited list, which is what a multivalue parameter sends to the query
I'm not sure how this works with text queries, but it works with stored procedures.
If the sub report is also used as a stand alone report you will need to add a new parameter to allow the user to send parameter values to #Emp_Id from a parameter the user can set
I guess you have not set the parameter in the sub report as Multi Select. If you have set the parameter in the sub report as multi select, then you could just send the parameter from the main report to the sub report as it is. See more at here
I used the following solution, which works in SSRS2016. This also works with text parameters.
Like suggested above, pass the parameter as a string to the subreport by JOINing the values.
Join(Parameters!EmpID, ",")
In your subreport, accept the parameter as text.
In the SQL of your subreport, use the string_split function of SQL 2016 to return a table of the values and simply join it to your main query. So basically if your parameter is named "EmpID_Multi" do
... JOIN (SELECT value FROM string_split ( #EmpID_Multi, ",")) mv ON mv.value= ...
Note: You might consider pulling the values into a temporary table for SQL optimization (sometimes the optimizer does funny things...).

SSRS Report Builder, is there a way to show values in filter?

Is there anyway to show the user what values are in each field so they can filter on these values?
How is the user supposed to know what values they want to filter if they can't see the values?
If I correctly understand what you are asking:
1) Set up a data set to retrieve the available values for your filter
SELECT DISTINCT MyFieldValue FROM MyTable
2) Create an SSRS parameter which will be used for the user to select a filter. Set it up to allow multiple values, and set the available values to use the data set created in step 1. Let's call this Step2Parameter.
3) Create your core data set for the report, and use the parameter from step 2.
Select MyID, MyFieldValue, Name, Blah FROM MyTable WHERE MyFieldValue in ( #Step2Parameter )
You can repeat this with multiple fields.
Does that get you in the right direction?
Also, make sure that in the Parameter Properties (right click your parameter and select Parameter Properties), that "Select Parameter Visibility" in the "General" menu is set to "Visible".