What is the SSRS Multi Value Data Type and how to use - reporting-services

I have a multi-select.
I think the underlying datatype is int || array(int). This is pretty frustrating that you have to do a check to see if a multi-value is present before jumping into an index. But how does this value get passed to SQL?
It's easy enough to use in a IN (#variable) statement. How else can it be used? Is it a string or a table. From my investigations it appears to be single table row with many un-named columns but I'm not really sure.
Finally, when you want to simulate a multi-select in a query inside visual studio, for example to "Refresh Fields" how do you do that? For example "1,2,3", {1,2,3} or #{1,2,3}. It's not (123) because that is -123.

It dpends what you are trying to do and in what context.
As you said, if you have a datset query that is a SQL script (as opposed to a stored proc) then you can use IN(#paramName). In this instance SSRS take the parameter values (not the labels) and injects them into the sql statement as a string e.g. '1,2,3'. The result would be IN(1,2,3). If you want to pass in a list of, say, countries then you would have to set the parameter values to be the same as the parameter labels So rather then Value =1, Label = Spain you would have Value = Spain and Label = Spain. Used in an IN() would generate something like IN('Spain', 'France').
If you try to do the same with a stored proc e.g. EXEC myProc #myParam, then the parameter values would be passed as a sing string which would then need to be split out by the proc.
If you just want to get a list of selected parmeter values or label shoing in your report then you can simply do something like
=JOIN(Parameters!myParam.Value, ",")
or
=JOIN(Parameters!myParam.Label, ",")
where "," is the delimiter
If you pop this expression in a text box, you'll get a list of the selected parmater values/labels

I think it's a kind of madness but I found a workaround to get a table of values from the results from SSRS. I query the IDs against a source table using IN(). I hope there is a better way of doing this?
SELECT [TblFeeBillingCycleID]
FROM [TblFeeBillingCycle]
WHERE [TblFeeBillingCycleID] IN(#intCycleId)

Related

SSRS 2008 :Is it possible to specify an entire where clause within parameter?

I have a table that I am building a report for. There are about 10 fields, but 4 of those fields may contain value(s) that users would want to filter the report by.
I was thinking I could create a parameter with a list of label/value pairs and the value portion of the parameter item would be an actual where clause for the underlying dataset like:
#filter
label/value
exceptions/where error_field like '%exception%'
counts/where count_field > 100
2016/where year_field = 2016
I tried dataset:
select error_field, count_field, year_field from mytable
#filter
I also tried(leaving where out of parameter value):
select error_field, count_field, year_field from mytable
where #filter
Both dataset queries failed to save. I am thinking I could include all the varying where clauses inside the dataset query statement, but it may require different parameters but how can they be empty unless I used 1=1 as default value. I only wanted to use a single parameter tho.
Any other ideas?
Thank you.
Your dataset query needs to be valid SQL. You can use an expression for the dataset, and work with the SSRS expression language to generate the SQL you need.
Something like:
="SELECT * FROM TABLE " + IIF(Value = True," WHERE 'A' = 'B'","")
However, I think they are a pain to work with. They are harder to understand, and take longer to maintain, and much easier to contain a mistake.
I find it easer and safer just to pass the parameters to a SQL Stored Procedure on the server, especially if you are using a TEXT BOX entry field.

Filter Multivalue Parameter on Dataset

So I have a multiple value parameter than contains 3 options. >250K, <250K, >2M.
I also have a table that consists of multiple columns.
. Because the parameter is a multivalue, i am having difficulties filtering the dataset.
I need to filter the dataset by checking, (if > 250K is selected, filter the dataset accordingly), (if < 250K is selected, filter the dataset accordingly) and (if > 2M is selected, filter the dataset accordingly).
I was told to use a join and split on the parameter within the (>250K condition, then do a contains to see if it contains any of the parameter values) but I am not as advanced in my knowledge of coding to be able to do that.
Any Suggestion? Thanks in Advance
I previously tried the method below but then i came to realise that it wont work because the parameter is a multi value.
I know its been a while since you raised this, you were on the right track but all you should need to do is add a filter to the Tablix on the field you will be filtering, use the 'in' operator and in the Value type [#Yourparametername] the square brackets and case sensitivity are important. Also ensure the expression type is correct, in your case it looks like you are using Integer. The image should help.
If you want to use multi-parameters, In the dataset, you can read parameter value using JOIN.
Example:
If you want to read multiple values for #MyParamter in a dataset given in the following example:
Dataset Parameters
you need to use =JOIN(Parameters!myMultiParamter.Value,",") as an expression to read all selected values in CSV form.
Expression
Now the #ParameterValues param has all selected values as comma separated values and you can use them in your dataset code as per design requirements.
Note: It's not necessary to use a comma but u can use anything you want to separate values.
Your sql query where should look like
Where
(
(0 IN (#Parameter) AND ValueColumn<250000)
OR
(1 IN (#Parameter) AND ValueColumn>=250000)
OR
(2 IN (#Parameter) AND ValueColumn>=2000000)
)
One parameter
Two parameters
All parameters
Once you return the value you can also use charindex or patindex* and look for where the value in your where clause is a pattern where the index number is > 0 . For instance if the returned string from SSRS is '01,02,03' and then your where clause has something like this right(field, 2) which would result in value '03'. you change your where clause to be where patindex('%' + right(field, 2) + '%', #returnedstring) > 0 which will give you results. The keeps you from having to parse apart the #returnedstring parameter in your sql code.

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.

MS Access 2010 query using tempvar inside IN() condition

I am trying to filter a query using a temporary variable that is inside an IN() condition. The temporary variable contains a list of text values. I am using the macro-builder tool in Access 2010.
Assume I have a query qryMain that produces:
Field1 Field2
1 A
4 B
2 C
3 D
without a WHERE clause. Using the clause
WHERE [tblMain].[Field2] IN([TempVars]![tmpField2])
to filter the query, the desired results are
Field1 Field2
1 A
4 B
when tmpField2 is set to "A,B". I set tmpField2 using an on-click event in form frmMain using SetTempVar and Requery the subform/subreport object sfrmMain that is based on qryMain. This is done via the MS macro-builder, not VBA.
Unfortunately, requerying sfrmMain produces an empty table rather than the expected results. Note that if I set tmpField2 to "A", then the requery macro works as expected.
I have tried multiple variations of initializing tmpField2, based on Access's double quote requirements, but still no success. My question is similar to this as-yet unanswered question, but my question involves passing the temp variable inside an IN() statement within the WHERE clause, without using VBA.
The problem is not actually due to TempVars. If your value list came from a form's text box instead of TempVars, the result would be the same.
For what you're attempting to do, IN () requires a hard-coded list of values:
SELECT m.Field1, m.Field2
FROM tblMain AS m
WHERE m.Field2 IN ('A','B');
But, instead of a hard-coded list of values, you want to supply the list dynamically when the query is run:
WHERE m.Field2 IN (something_dynamic);
Unfortunately, Access will not cooperate. Whatever you supply for something_dynamic, Access will interpret it to be only one value ... not a list of values. And it doesn't matter what method you use to supply something_dynamic ... a TempVar, a text box, a formal query parameter, a custom VBA function which returns a string containing a list of values ... that list will be evaluated as only a single value.
If you were willing to use VBA, you could write the query at runtime to include a hard-coded value list before executing it. Since you want to avoid VBA, you can try something like this ...
WHERE InStr(1, [TempVars]![tmpField2], "'" & m.Field2 & "'") > 0
Note that approach requires quoting text values within tmpField2: 'A','B'
Also beware that approach could be painfully slow with a large table. Access would need to evaluate that InStr expression for every row in the table.

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!