"Select All" with SSRS 2008 Parameters - sql-server-2008

I want a parameter to load available values from a query (or whatever) and "allow multiple values." When I do so the list begins with "Select All."
That's great, but there appears to be no way to default the parameter to "Select All" which is not acceptable in my case. This particular report will have 8 optional parameters and if htey have to select "Select All" multiple times, this is hardly optional.
Therefore, I create my own "..All" option and the code to accept it. I can default to that, but then the user sees:
(Select All)
..All
This looks unprofessional. I've scoured the net and there doesn't appear to be an answer to this problem.
Is there any way to suppress (Select All) or achieve what I need? Any ideas?

Actually, the answer turned out to be that you have to set your Available Values and Default Values to the same Dataset and field.
If you do that, SSRS automatically selects every option in the list. It's not pretty, but it works.
Coincidentally you have to handle nulls in your dataset query too and replace them with some value such as "None." SSRS parameters will not allow the user to select "Allow multiple values" and "allow null values" at the same time. If your field contains nulls, SSRS will not throw an error but it will not default either.
I'm going to follow up with a blog post on this problem in the near future.

You can also use the Split() function to return multiple values.
For example, if the dataset is a bunch of varchars like
SELECT 'A' UNION SELECT 'B'
The following default value to select all for the multiple value parameter would be:
=Split("A,B",",")

Related

Report Server: how to select everything if parameter = null or blank (allow multiple values is turned on)

How to return everything in Report Server if parameter value is blank or null?
The solution:
SELECT some_column
FROM your_table
WHERE (#y is null or y >= #y)
Doesn't work in SSRS since "Allow null value" cannot be turned on, when parameter "Allow multiple values" is turned on.
Thank you.
There are a couple of ways around this but the simplest is just to use the "Select All" option at appears at the top of multi-value parameter lists. If you need this to be the default then set the default and available value to the same query.
The "Select All" option is shown automatically for multi-value parameters when there is more than a single value in the list as shown here..
Other ways are similar, for instance you can add a value to the top of your parameter's available values list that has a label called "All" or something like that and a value you can look for in your query (e.g. -1).
BTW: Your sample code would not work with a multivalue parameter if used directly in the dataset query you would normally do something like
SELECT some_column
FROM your_table
WHERE (#y =-1 OR y IN(#y))

Default several values of Parameter, SSRS

I am trying to predefine some report parameter properties in SSRS, where the dataset is retrieved using DAX. I want one parameter, that selects an area code, to be default set as "(SELECT ALL)". How can I do this? If I try to just select it from the default value list the best I get is:
=First(Fields!City_Areacode_.Value, "AreaDetails")
I don't want the First value, however, but all values. Is my best option to "hard code" all the values in there as a list?
The correct way is to select "Get values from a query" and then select the correct dataset and column instead of "Specify values".

Adding optional filter in SSRS 2008

I am trying to add an optional filter on a text field in a report. I have tried setting it up in the dataset but it treats it as a required filter so if it is not populated, no results are returned. It needs to use the Like operator. Any advice?
As I was typing out a work-around to this problem, I realized an incredibly easy solution (now that I understand better how it works).
Here's what I did:
Since Hong pointed out that all filter conditions must be met, I reversed my thinking. I moved my existing "IN" filters to the query and fed the parameter directly to the query. Then I created by "LIKE" text filter on the report which a default value of "*" so it would immediately return everything.
Here's what I could've done:
Just the last part. Added the "LIKE" filter with a default value of "*" so it immediately returned everything.
I also agree that most of the time it's best to send the params back to SQL. Since that's not what the OP is asking, here is the best option I have found for doing this. And it is actually quite simple.
Add your parameter with the appropriate data type. Let's use the
example of a "City" in this case (a text/string field).
Check "Allow Nulls" on the parameter.
Add a filter to either a tablix, table or dataset.
In the expression, select the field you want to filter on. Select the appropriate operator, in my example of a data set with Cities, in the Value put in this:
=IIF((Parameters!City.Value Is Nothing), Fields!City.Value, Parameters!City.Value)
I don't think you can make an optional filter in DataSet Properties/Filters, adding filters there means returning results that match ALL filter contiditions, so it is "AND" logical relation among all filters, not "OR".
My sugguestion is to use filter in query designer of the dataset, where you can define "OR" relations to filter out data. For instance: Your_Text_Field="SomeValue" OR Your_Text_Field is Empty.
Although I agree that most of the time it is best to send the parameters back to the stored procedure or data layer to reduce the amount of data returned, I have a case where it is just as easy to do the parameter handling in the RDL file via a filter. Due to this unique situation I found this solution which gives you a way to create an Optional filter in the RDL file.
http://www.andrewshough.com/development/sqlserver/ssrs/optional-filter-in-ssrs/
It is a great blog post with easy step by step instructions on how to create an optional filter.
Please Note: This is NOT my blog but I though this solution was great for what I needed and I hope it helps someone else when they google for "optional filter in SSRS" like I did.
I found a post which solved my problem setting the filter for a report-consumer to a) all multivalue fields being selected so the user b) could specify his/her selection if necessary.
Kasim 8 Dec 2010 8:55 AM #
In reports when we want to default the multivalue parameter to 'Select All' following are the steps.
Open the Report parameter window from the Report menu.
Select the Report parameter from the left handside of the window.
Select 'Multi-value' checkbox and appropriate 'Available values'.
Under default values select 'From Query' radio button'.
Select the appropriate 'Dataset'.
Select appropriate 'Value Field'.
Save the Report and select Preview Tab. You will find all the items selected in the multivalue >parameter list and the result displayed for all the selected items.
found on: http://blogs.msdn.com/b/bimusings/archive/2007/05/07/how-do-you-set-select-all-as-the-default-for-multi-value-parameters-in-reporting-services.aspx
(The Post came up in the comments quite in the middle.)
You can accomplish this by using an expression on the dataset filter.
Check this

SSRS: Can I know if user selected "ALL" in multivalued param?

Customer wants me to repeat the parameter values in the page header of the report. But if they just choose "Select All" on a multi-valued parameter, they want the text "Any" listed.
For example, one parameter has a fixed set of 9 values. I hard-coded the expression for a text box to:
="Room Size: " &
iif(Parameters!pRoomCap.Count=9,
"Any",
Join(Parameters!pRoomCap.Value, ", "))
How can I do this if the parameter source is a query of unknown size?
Try this out. You need to compare the total number of parameters in the dataset to the count of selected parameters. The following assumes that your multivalue parameter is using a dataset called "dsRoomSizes"
="Room Size: "
& iif(Parameters!pRoomCap.Count = count(Fields!pRoomCap.Value,"dsRoomSizes"),
"Any",
Join(Parameters!pRoomCap.Value, ", "))
This expression will work in the page header/footer.
UPDATE
In the interests of finding a solution to your problem, the following should work for you. It feels hackish and I encourage you to keep research alternative methods but this will work:
Create a second multivalue parameter and name it something like "pRoomCap_hidden".
The source of the parameter is the exact same query
In the parameter properties, setting the default values to the same query
Important: Set the parameter visibility to hidden
This will create a second multivalue parameter in your report that is exactly the same as your initial multivalue parameter only this parameter list will have all values selected by default.
Enter the following expression in a textbox in your header:
=IIF(Parameters!pRoomCap.Count = Parameters!pRoomCap_hidden.Count,"All",Join(Parameters!ReportParameter1.Value,", "))
The above will compare the selected values in each parameter list. If the lists contain the same selected values then that indicates that "All" have been selected in the first list.
Like I said, it is hackish but it definitely works. Until you are upgraded to 2008, this might not be a bad workaround for you.
Can you compare the count of the parameter to the count of the dataset you pull the parameter values from?
I unioned my dataset for the parameters with one which I created manually with a "select" statement - I was then able to force the value to be something like -1 or null.
Then simply check if the parameter contains -1 or null and replace the value in the header with the replacement text.
BTW- I am now using SSRS 2008 R2 and this solution worked for me. My report uses three datasets; but only one in the tabilx that I needed to hide a row in. After long hours of searching and many, many, many unhelpful for wrong answers; the solution of creating a identical parameter only hidden (I marked it as internal) and then comparing to the exposed one is brilliant and easy.
Thank you very much!

SQL Server Reporting Services - Set default value for multi-value report parameter

I have a report in SSRS and one of the parameters I use is Cities. The user can select from a list of cities to pull the report for that location, or multiple locations. My datset is simply a select * from tblCities. When I run the report, I do see that one of the options is "Select All." But, I'm wondering - is there a way I can get this "Select All" option as the default value, so that by default all cities are selected?
And, along those lines, but a separate question - is it possible to make this drop-down optional? I have tried the allow NULLS checkbox, but for multi-value parameters, it seems SSRS does not allow this.
FYI - I have only begun using SSRS; know very little about it.
is there a way I can get this "Select All" option as the default value, so that by default all cities are selected?
Yes you can.
Open the Report Parameters dialog: Layout tab, right click anywhere on the canvas that is not the report, select Report Parameters
Select the parameter (cities in this case), from the list on the left
Select the appropriate default setting in the default section, lower righthand corner
One option is where you can statically define a value. IE: =0 or whatever the value is for the Select All option. FYI: I've found that what works in the Visual Studio preview doesn't work when live.
Another option is if the list of cities comes from a stored proc, you order the output of the sproc so Select All is at the top of the list. Then you select the radio button under the static value one (can't remember, not at work to check ATM) - you'll have to select the dataset the sproc is associated with, then the column that the value comes from.
is it possible to make this drop-down optional?
When you say "multi-value", are you actually able to select multiple values from the list? IME, all you get is a drop down & can only select one of the options available.
Allowing null is just an accepted value - the optionality is really handled in the query so that if a sentinel value is provided then the criteria isn't included in the query. IE:
AND (#cities IS NULL OR t.city = #cities)
That's quick & literally dirty. ORs are poor performance.
Make these changes to the specified report parameter:
In order to have all fields selected, make the [dataset] and [valuefield] at "Available values:" equal to the [dataset] and [valuefield] at "Default Values" (assuming you have a query for determing this)
In reports when we want to default the multivalue parameter to 'Select All' following are the steps.
Open the Report parameter window from the Report menu.
Select the Report parameter from the left handside of the window.
Select 'Multi-value' checkbox and appropriate 'Available values'.
Under default values select 'From Query' radio button'.
Select the appropriate 'Dataset'.
Select appropriate 'Value Field'.
Save the Report and select Preview Tab. You will find all the items selected in the multivalue parameter list and the result displayed for all the selected items.
Go to the either the Data tab or the
Layout tab.
From the Report menu, select Report
Parameters
Select the desired parameters, in
this example, cities
In the lower right hand region of the
screen, set the Default values radio
button.
Set the Dataset and Value field drop
down lists to the exact same options
as the DataSet and Value field sections from the Available Values settings above.
This assumes that you are using the "From Query" option under "Available values" If you are using the "Non-queried", see the answer by OMG Ponies.