Passing multiple values using URL to a drop down parameter in SSRS - reporting-services

I am trying to pass multiple values for a parameter in ssrs which is delimited by ','.Limiting the result data set using where condition using split function in stored proc, this gives me results of my report data set
WHERE YEAR(a.month_start_date)IN (SELECT Value FROM dbo.FnSplit(#year,','))
--AND datename(month,month_start_date) IN (SELECT Value FROM dbo.FnSplit(#month,','))
AND b1.branch_cd IN (SELECT Value FROM dbo.FnSplit(#branch,','))
I created a data set to get available values for year filter
Configured the parameter to get available values from my filter data set and also checked option to "Allow multiple values"
Select distinct year(month_start_date) as Year
From [DB].[dbo].[table]
Then I also limited my report data set to accept parameters with following condition.I configured parameter to accept the following value
=Join(Parameters!year.Value,",")
I pass in values in url
http://<servername>/ReportServer/Pages/ReportViewer.aspx?<reportname>rs:Command=Render&year=2012,2013,2014
My filter does not select the values passed thru the url. The report only shows me the list of values in drop down but does not select the values parsed thru url
I am not sure if I am missing anything else. Please suggest.
Thanks!

The issue here is that your URL is constructed incorrectly. You are trying to pass througth the years as a single parameter and that isn't how it works. Pass it through as a whole heap of parameters and then let the reporting server put it together and put it into the SQL.
Your URL should look like this (I changed the : to %3a and broke up the year parameter)
http://<servername>/ReportServer/Pages/ReportViewer.aspx?<reportname>rs%3aCommand=Render&year=2012&year=2013&year=2014
I hope this helps someone out.

Related

SSRS - multi-value parameter is throwing error when more than one value is selected

I am using Visual Studios 2015 with SSDT installed. I cannot show my query as it has confidential columns in it. Let's just say I have two temporary tables that gather general data which are joined in the select statement and uses a where clause that accepts a multi-value parameter of text datatype (column is char(8)) to filter the information in the report. I have checked allow multiple values in the parameter properties. There are no available values, the user types the values in. (I've also tried supplying values in drop down list with same results).
Where smpl_lvl_cd in (#SampleLevel)
I would think this is quite simple and when the user selects one value, everything works well. As soon as you choose more than one value, you get the error "An expression of non-Boolean type specified in a context where a condition is expected, near ','."
For example: Sample Levels 'Q' and 'V' are selected. The way I understand it, SSRS send 'Q,V' to the query. (Or does it send "Q,V,'?) With this in mind, I've tried using:
Where smpl_lvl_cd in (select value from string_split(#SampeLevel, ','))
with similar results "Procedure or function string_split has too many arguments specified....." followed by the same Boolean message.
This parameter is not being sent to a stored procedure but I've tried using the join function on the parameter in combination with the string_split in the query. I end up getting no data for more than one selection.
Please help.
See this article: SSRS multi-value parameter using a stored procedure. You have to change your multi-valued parameter array into a string before sending into your dataset. therefore send the expression =Join(SampeLevel!Value,",") instead of [#SampeLevel]

Report Builder - Use one dataset in the where clause of the query for another dataset

I'm using SQL Server Report Builder 2014.
DatasetA is created from TableA in DatasourceA and contains a single column of IDs.
DatasetB, on which my report is based, needs to have all rows from TableB in DatasourceB WHERE TableB.ID IN (DatasetA).
I've done lots of Google'ing, but cannot find a solution that works. Suggestions?
For this you could use a hidden parameter in the report, lets call is ParamA. Populate ParamA using DatasetA, set it as a multi-select parameter and set the defaults using DatasetA i.e. all items will be selected.
Then in DatasetB have where id in (#ParamA)
As I know, when you use where name in (#aa) in query designer(text mode) and click OK, it will prompt like below
You could hard code in it, it seems to support single parameter to test in designer, but when you preview it in report, you could pass multiple parameters. You could click OK to ignore it or pass hard code in it to see whether parameters could work or not.
In addition, if you want to show dataset A's value in parameter list, you could set available value in parameter properties (get values from query)

Pad user input with zeros in a multiple value parameter

Is there a way to pad numbers in a multiple value parameter to make them have 8 characters in length? Right now I am using:
=Right("00000000" & Parameters!Accounts.Value,8)
in an invisible parameter then that parameter is passed to the in part of my query. When I have, multiple values unchecked it works properly, but as soon as I turn on multiple values I get an error
The DefaultValue expression for the report parameter ‘ActualAccounts’ contains an error: Operator ‘&’ is not defined for string “00000000” and type ‘Object()’.”
I want the user to be able to paste in a list of accounts like:
93874
93932128
3838
And then it queries the database as
00093874
93932128
00003838
Here is an approach that could work for you.
First, grab the udf_Split user-defined function (UDF) from the this question's answer. With this UDF you to pass the delimited string as a parameter, and it will return a table with a row for each value. This is how SSRS sends the data to SQL Server when it comes to multi value parameters.
Once you have that in place, then all you need to do is use that UDF in the following manner.
DECLARE #ActualAccounts varchar(100) = '93874,93932128,3838'
SELECT RIGHT('00000000' + RTRIM(LTRIM(Value)), 8) AS Accounts
FROM dbo.udf_Split(#ActualAccounts, ',');
Results:
Accounts
--------
00093874
93932128
00003838
Then you could use this in the SQL for the report
SELECT *
FROM Accounts
WHERE AccountNumber IN (SELECT RIGHT('00000000' + RTRIM(LTRIM(Value)), 8)
FROM dbo.udf_Split(#ActualAccounts, ','));
This answer assumes the name of the SSRS parameter is ActualAccounts. You should be able to fit this into a stored procedure, if that is what you are using. It should work in straight SQL if you have that embedded in the RDL, too.
Hope this helps out.

Report Builder 3.0 Forward Dependency Report Parameter

I have a report that I am working on that will do the following:
Return results based first on the community selected by the user.
Filter to find alike addresses within the community, based on the number of square feet at each address.
Set the end date (a column within the data table) to a user defined parameter for use in a WHERE at the end of the query.
The relevant information is stored in the following places:
Community: ub_subdivision.descr
Address: ub_serv_loc_addr.location_addr
SqFt: arp_ops.dbo.vw_ub_serv_loc_classifications.SqFt
I have setup the query with 3 parameters:
#Community
#Months
#Address
When the user is running the report, the following should happen (in this order):
The community parameter should populate the values stored in ub_subdivision.descr and allow the user to select the community they want from that list.
The address parameter should populate the values within the selected community from step 1, and allow the user to select the address they want from that list.
Based on the selected address, the query should store the value of the SqFt related to this address and use that in the WHERE statement as follows: WHERE (arp_ops.dbo.vw_ub_serv_loc_classifications.SqFt = #Address)
The months parameter should allow for user input to define how many months of data they want. This parameter is called in the query in the WHERE statement: WHERE (ub_bill_run.def_end_dt > DATEADD(m, -#Months, GETDATE())).
If I save the dataset and create a "table report" in Report Builder 3.0 it does the job of recognizing the various parameters and loading them into the Parameters folder and into the Datasets' parameters.
The problem I have is that I am not able to change the parameter properties to display Available Values and select "get from a query". If I go this route, and try to run the query I get an error that I am using "forward dependencies".
I need the #Address parameter to display the address field as the label, but store the sqft field as the value. This is the way I know how to do this and, unfortunately, it doesn't seem to work.
I would appreciate any insight anyone may have.
Thanks!
John
There is one way to solve this make sure the order should be in the order of
#Community
#Months
#Address
change order to:
#Community
#Address
#Months
just delete existing #month and again add it manually and save it.
i hope it will work for you.
You cannot have parameters based on your main data set.
The forward dependency error is caused because your data set is to be filtered by your parameter, yet it is depending on the same data set to find its' set of values. This is a sort of paradox.
When using queries to define the set of values for your parameters, make sure you create a new data set for each parameter.
Next, make sure the parameters are listed in the order you want them to run. Within the data sets for your parameters, you may use where clauses to make them dependent on one another in the order that they run.
In this example:
Parameter data set for Community:
SELECT DISTINCT ub_subdivision.descr
FROM [YOUR JOINED TABLES]
Parameter data set for addresses:
SELECT DISTINCT ub_serv_loc_addr.location_addr
FROM [YOUR JOINED TABLES]
WHERE ub_subdivision.descr IN (#Community)
Parameter data set for SqFt:
SELECT DISTINCT SqFt
FROM [YOUR JOINED TABLES]
WHERE ub_subdivision.descr IN (#Community)
AND ub_serv_loc_addr.location_addr IN (#Address)
You should also make a month data set for your #month parameter, however it is not dependent on the other parameters so I will leave that to you.
Hope this helps!

Fields cannot be used in report parameter expression

I have to set the start_date of my report depending of a report parameter. The time stamps are calculated in a database query.
My expression looks like this:
=SWITCH (
Parameters!report_type.Value = 1,First(Fields!daily_start.Value, "Timestamps")
,Parameters!report_type.Value = 2,First(Fields!weekly_start.Value, "Timestamps")
,Parameters!report_type.Value = 3,First(Fields!monthly_start.Value, "Timestamps")
)
Unfortunately I get the error message:
A value expression used for the report parameter 'time_from' refers to a field. Fields cannot be used in report parameter expression
I know, that this is not allowed because SSRS cannot be sure in which order datasets are called. But I think this is not dangerous.
All time stamps are received by query without parameter. The parameter report_type is selected by a user before the report will be generated.
Can someone give me a hint for a workaround?
Here's the workaround - get the value using SQL.
Create a new Dataset called StartDates:
SELECT CASE
WHEN #report_type = 1 THEN daily_start
WHEN #report_type = 2 THEN weekly_start
WHEN #report_type = 3 THEN monthly_start
END AS StartDate
FROM MyTable
You already have the #report_type and #time_from parameters. With the #time_from parameter, set its Default Values to Get values from a query using the StartDates dataset and the Value field StartDate.
Now, you'd think this might be enough to make it work - you're referencing this query as the default value and as you change the #report_type parameter the other parameters refresh, but the first date in the #time_from parameter never changes. That's because the refresh happens on the Available Values query, not on the Default Values query.
So you also need to wire up the Available Values query to the StartDates query. Now your query will fire on the change of #report_type and the default value will be set to the appropriate date for your selection.
I switched from a query to Stored Procedure and was getting this error. Things I tried:
Ensured I had sufficient permission on the database (you need EXEC rights or DBO to run teh sproc)
Delete the existing parameters (and then use refresh fields to refresh/get the correctly named ones back)
Remove the square brackets around the stored procedure if you've specified that
Sometimes, Expressions can get a bit verbose. I have created a Report Code Function and then used that as the Parameter Value.
For example, I created a Code function called "CalculateDateSet" and then set the Report Parameter to this expression:
"=Code.CalculateDateSet(Parameters!Month.Value, Parameters!Year.Value"