Making parameter Optional with multivalue parameter in SSRS? - sql

I have a parameter in which I have selected "Allow Multiple Values" at the same time how can i make the same parameter as optional. For example if customer wants to leave the parameter value as blank he can on the other hand if customer wants to select any value then it is allowed. In Case any of the parameter is left blank the code should run
I am using below mentioned query where i want to make enrollment_type the parameter where i want above mentioned conditions
Where (School IN (#school))
AND (School_Year IN (#schoolyear))
AND ((EnrollmentType IN (#EnrollmentType)) OR ('' IN (#EnrollmentType)))
OR (Grade IN (#Grade))

you could in ssrs >> parameter properties on general tab select option for allow blank values is sql you need :
Where (School IN (#school) or #school='' )
you can also do the same thing with allow null values
Where (School IN (#school) or #school is null )

I guess you are trying to make your enrollment_type parameter as optional to the users. If you are looking to make no filter on enrollment_type by default, you can set the default setting of the parameter.
If you are populating your parameter value from query, set the default value exactly same as available values i.e. parameter>Default Values>Get Value from Query>Dataset>Value
By setting both the available values and default values same. You will not be asked to select any value for enrollment_type and the Select All option will be automatically checked.
You need to add EnrollmentType IN (#EnrollmentType) in your dataset.

Related

Report Builder - 3 Parameters all in one Query. Forward dependencies are not valid

I have an issue with building my report, I have 3 params and all 3 are in a query, they are supposed to get their values from the "drop down menus" before running the reports and are used in a where cluase to get specific stuff from the database. However I can seem to get it to work.
Example Query
Select * from [Table]
Where ID = #ID and DateFrom = #DateFrom and DateTo = #DateTo
order by ID
This is the query, I tried changing the orders of the params but it doesnt work.
Error:
The report parameter 'ID' has a DefaultValue or a ValidValue that depends on the report parameter "ID". Forward dependencies are not valid.
Based on the error you reported...
"Error: The report parameter 'ID' has a DefaultValue or a ValidValue that depends on the report parameter "ID". Forward dependencies are not valid."
I suspect your ID parameter's valid values are taken from a dataset query. The dataset query uses a parameter called #ID . You cannot populate values for a parameter if the parameter you are trying to populate is required by the query.
If you are trying to get a list of available ID's to populate the ID parameter drop down then you need to create a separate dataset for this. The dataset query would be something simple like.
SELECT DISTINCT ID FROM [Table] ORDER BY ID
You can then change your ID parameter's "Available Values" dataset to point to this new dataset.
If this does not help, show you report design (the parameters at least), the parameters properties and the dataset queries for each one. Your issue should be clear once all that is visible.

Make Null Values Display As Blank While Still Maintaining Number Format In MS Access?

I am writing a query in MS Access where I pull numerical data from a table that includes null values, and I am trying to make the null values appear as blanks (or any non-numerical string would be fine), yet still be able to include them in functions as if they were zero.
Originally my query looked like
Select CDbl(Nz([tbl.column],"")) AS Alias
Which made nulls appear as errors and didn't allow me to include them in sum functions.
Now the code I am using is
Select CDbl(Nz([tbl.column],0)) AS Alias
Which allows me to include them in sums but they are displayed as 0s.
I have also already tried setting the field properties to be number with default value as blank, but this has not helped either.
Any suggestions would be greatly appreciated.
Use this to replace null with zero:
SELECT IIf(IsNull([tbl.column]),0,[tbl.column]) AS Alias
FROM tbl;
It's not that complicated. If you want to display "blanks" for Null, that's the default behaviour:
Select tbl.column AS Alias
If you for some processing wish to handle the Null values as zero, use a separate alias:
Select Nz(tbl.column, 0) AS NumericAlias
But for Sum it makes no difference; Null is ignored, and zero adds nothing to the sum.

SSRS: When Multi-value Parameter = Select ALL remove filter in Script

I have a report that has multiple multi-value parameter. What I wanted to do is if the parameter is = Select All I'll remove that parameter to my SQL Script.
Example is I have a Product group and Product Name parameter and what I want is if the user selects all the product group my script will be like:
SELECT * FROM TABLE WHERE PRODUCT_NAME IN (#ProductName)
While if the user did not select all Product Group, my script will be like:
SELECT * FROM TABLE WHERE PRODUCT_NAME IN (#ProductName)
AND PRODUCT_GROUP IN (#ProductGroup)
I want to know how Can I detect when multi-value parameter is = Select All. I think it will really help the loading time of the tool if I just remove the filter on my script.
As far as I know, you cannot detect when "Select All" has been checked by the user.
To remove the filter completely when the user selects all the choices in a multi-valued parameter you would have to employ logic in your stored procedure that checks to see if all the choices were passed to it in the parameter, and if so, don't use the parameter at all in the main query.
You can add your own ALL value to the parameter. In the dataset query check if the user have selected 'ALL' if so don't use the parameter.
Something like this:
IF ('ALL' IN #ProductGroup)
BEGIN
SELECT * FROM TABLE WHERE PRODUCT_NAME IN (#ProductName)
END
ELSE
SELECT * FROM TABLE WHERE PRODUCT_NAME IN (#ProductName)
AND PRODUCT_GROUP IN (#ProductGroup)
It is not tested but should work
If your parameter is based on a dataset, you can compare the numbers of elements selected in the parameter vs. the number of items in the dataset for the parameter.
=IIF(Parameters!AREA.Count = CountRows("Areas"), "ALL", "Some")

Multi-value parameter truncation

On my SSRS report I have a multi-value parameter which contains 250+ uniqueidentifier data type values. This works fine with a small selection of values in the parameter dropdown, but when user chooses (select all), they get this error:
An error occurred during local report processing.
String or binary data would be truncated.
Each uniqueidentifier field is 36 characters long, which means 250 of them added together result in a 9000 character string. This is what causes the truncation to occur.
What approach should I take to handle this situation?
Edit:
Couple snapshots of the stored procedure:
ALTER PROCEDURE [dbo].[spReport]
#StartDate as datetime
,#EndDate as datetime
,#LocationId uniqueidentifier
,#UserIds uniqueidentifier
#UserIds is the multi-value parameter. It is used in the where clause of the query:
WHERE (U.UserId IN (#UserIds) OR #UserIds IS NULL)
You can't use an SSRS multi-value parameter with a stored procedure like that. You'll need to join the values in the report, pass them as a varchar(max), and then split them in the stored procedure:
https://stackoverflow.com/a/9862901/124386
http://www.codeulike.com/2012/03/ssrs-multi-value-parameters-with-less.html
SSRS does have a limit on the size of multi-value parameters. I can't remember what it is off the top of my head, but I think you are well beyond it. (SSRS converts the multi-value parameter to a comma separated string and replaces the occurances of the variable name in the query with the string.)
So as mentioned in the comments, you've got two problems:
SP's can't take multi-value parameters directly from SSRS. You'll need to do some manipulation.
Your overall parameter length. This may require a little bit of creativity to solve. Some options:
Can you supply either a separate parameter or a special value in your existing parameter for <All Users> and then check for this in the SP, returning all values in that case. If the query is directly in SSRS (instead of a SP) something like this would work:
...WHERE ( U.UserId in ( #UserIds) OR '<All Users>' in ( #UserIds ) )
...
Can you filter the number of items in your parameter, based on earlier parameters? Such as have the user select a date range and/or department, and only return UIDs that match that range?
Another approach is to create a user defined table type and use that instead of a varchar to pass in the selected values.

For SSRS in Visual Studio 2008, how can I make a variable accept multiple values as well as a single value?

I'm making a report with Visual Studio 2008, pulling the info from a table in a database. Let's say I just want to show the Type of employee (which is represented by an int, say 1-10) and their Name. Then my dataset would be this query:
SELECT Type, Name
FROM Employees
WHERE Type = #Type
This is SSRS, so I do not need to declare or set the variable (correct me if I'm wrong). When I run the report, it will give me an option to type in an int for the Type and it will create the corresponding report. My question is how can I set it so that I can type 1,2,3 in for the Type so that I get a report with those types of employees? So having the int variable be able to accept a list of ints or just one int. Essentially the "resulting query" from that example would look like this:
SELECT Type, Name
FROM Employees
WHERE Type = 1 AND Type = 2 AND Type = 3
On the left side in the Report Data window under the Parameters folder, right click the variable, hit Parameter Properties, then check 'Allow Multiple Values' and select the correct datatype in the dropdown. I'm not sure why it decides to make a dropdown when you run the report, and you have to enter the values each on their own line instead of separated by commas, but it seems to work fine. Then just change the WHERE clause in your dataset from WHERE Type = #Type to WHERE Type IN (#Type). I don't know if the parentheses are necessary.
Also if you create a separate dataset that will present certain values you can have those show up instead of having to type them out. For example, create a dataset that contains this query
SELECT DISTINCT Type
FROM Employees
ORDER BY Type
This will create a list of distinct values for type that you can check/uncheck. You can make it more complex obviously as well.