Reporting Services - hide table row based upon report parameter value - reporting-services

i am showing jobid in my report. i want that if job ID are this 02,07.11,19,21,29,31,40 etc then those report rows will not be shown. i know how to hide rows writing expression but i just need to know if there any short cut way to say that my job is are 02,07.11,19,21,29,31,40.
still i am doing like =IIF(Fields!JID.Value = 02 or Fields!JID.Value = 07 or Fields!JID.Value = 11 or Fields!JID.Value = 19, True, False)
is there any way like =IIF(Fields!JID.Value in (02,07.11,19,21,29,31,40), True, False)
if i send job id as a parameter value send from calling environment like "02,07.11,19,21,29,31,40" then how to di it.
please let me inform.

Will it work for your purposes to handle this in SQL? You have a couple options...
Option 1
Set up a multi-valued, string parameter in your report called #JIDValues.
SQL sprocs do not accept arrays of values, so you will need to pass this as a string array to your sproc. In order to do this, you will need to join your values together in your report code that executes the stored procedure.
JOIN(Parameters!SiteGroupList.Value, ",") & "'"
Inside the sproc (or the report depending on your preference) you will need to append and prepend commas to your string so that the following will work for your values on the ends as well as in the middle of the string. The following WHERE clause will be able to determine if a specific Job ID is contained in the comma delimited string you passed to the sproc.
WHERE #JIDValues LIKE '%,' + LTRIM(RTRIM(STR(tableA.JID))) + ',%'
Option 2
Alternatively, if this is a static list, you could hard-code your sproc to exclude them.

Related

SSRS Cascading Parameters - Remove GUID from Value

I am currently trying to work on fixing some cascading parameter issues I am having.
We recently put in a fix to a few SSRS reports that help with rerunning cascading parameters when the parent parameter is changed, if it helps, here is the instructions we followed to implement this: Cascading Parameters.
The main structure for most of our reports works like this:
#Hierarchy, select whether you want to filter by "Market" or "Region"
#HierarchySelection, select which markets or regions you want to filter by
#PropertyInternal, gets used to refresh #Property automatically each time #HierarchySelection is changed, this is populated by a SQL dataset
#Property, select which properties you want within those given markets or regions, the defaults are set up as Parameters.PropertyInternal.Value and get refreshed each time #HierarchySelection is changed
In order to get #Property to refresh properly, we have to feed #PropertyInterval with a NEWID() so it sees it as a new value each time it runs, so the value is CONCAT( Property, "|", NEWID() )...Property is always a 4 digit character
The issue I am having is that now is that subscriptions are failing because the Property parameter gets refreshed and unselects the values. Or if I have to feed it values, I can't exactly feed the NEWID() as I am unaware of what the value will be when the report is run.
My only thought is to try and remove the GUID from #PropertyInternal and feed that value to #Property instead, but either that is not possible or I just cannot figure out the syntax.
Any one have any better ideas for how I am handling this or if there is a way to remove the GUID?
I am essentially looking for something similar to this if possible, but getting the error below it.
=SPLIT(LEFT(JOIN(Parameters!PropertyInternal.Value,","), 4),",")
The report parameter 'Property' has expression-based ValidValues. The sizes of the value and the label (multi-value) arrays have to be identical. (rsInvalidValidValueList)
Public Function CommaSeparatedParam(ByVal strArray As Object()) As String
Dim returnStr As String = String.Empty
For Each str As String In strArray
returnStr = returnStr + Mid(str, 1, InStr(str, "|") - 1) + ","
Next
Return Left(returnStr, Len(returnStr) - 1)
End Function

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

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)

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.

SSRS Switch statement expression for multi value parameters

I have the following switch statement within an SSRS report, but it errors out when I run the report.
Basically Parameter 1 is a multi value parameter, and when the parameter has two values selected where they are two distinct values, I want a certain text to appear.
=SWITCH(Parameters!Parameter1.Count = 2 AND Parameters!Parameter1.Value(0) = "TEXT1-NY" AND Parameters!Parameter1.Value(1) = "TEXT2-LA" , "Combined (NY & LA)"
, True, JOIN(Parameters!Parameter1.Label,"& ")
)
Additionally, regardless of the numbers that are selected (i.e if there were 6 parameters that were selected), is it possible that these two parameters would be replaced with that particular text followed by , and then names of other parameter values?
First of all, good job working out the expression that you have. You're on the right track, but expressions don't have a programmatic way to loop through the values of the parameter.
One option to do specifically what you asked would be to add a custom function to the Code section of your report that could loop through the parameter values.
Another option would be to simply UNION this "Combined (NY & LA)" value to your dataset so that it is available as one of the options.

Need Help on SSRS SPLIT function

Hi All I need your advice,
1) I have a dynamic string which changes each time.
for example today the string will be "ItemA,ItemB,ItemC" and tomorrow it will be "itemA,ItemB" only.
2) I have an SSRS report which has 3 columns
3) I want to split this string "ItemA,ItemB,ItemC" and want to show split substrings in these 3 columns of ssrs table. the Delimiter is "," (comma)
4) I had used
=Split("ItemA,ItemB,ItemC",",").GetValue(0) in the first column of the report
=Split("ItemA,ItemB,ItemC",",").GetValue(1) in the second column of the report
=Split("ItemA,ItemB,ItemC",",").GetValue(2) in the third column of the report
5) everything works fine until my string is "ItemA,ItemB,ItemC" ,
BUT WHEN MY STRING CHANGES TO "ItemA,ItemB" I am seeing "#Error" in the third column.
I understood the error, for
=Split("ItemA,ItemB,ItemC",",").GetValue(2) we don't have any value because the string now has only 2 values after applying split function.
Is there any way i can avoid #Error in the third column.
NOTE: I have to compulsorily use 3 columns in the ssrs report.
I had tried using =Replace(Split("ItemA,ItemB",",").GetValue(2),"#Error","NULL") in the third column but that also wont worked.
This is similar to the divide by zero issue in using IIF statements. The problem is that IIF is not an expression, it is a function with three parameters:
IIF(Condition, ValueIfTrue, ValueIfFalse)
Accordingly, ALL parameters are evaluated BEFORE being passed to the function, which results in the error because the erroneous expression is still evaluated even when the condition should mean that it isn't.
I can't see a way to use the usual workaround tha solves the problem in the divide by zero case. What we need is a real language that doesn't have this problem. Fortunately, this is availble in the form of custom code.
Do the following:
Right-click on an area of the report surface that has no report objects
Select Report Properties
Click on the Code tab
Insert the following code:
Public Function ExtractCode(Combined As String, Position As Integer) As String
if (Split(Combined, ",").Length >= Position) Then
Return Split(Combined, ",").GetValue(Position-1)
Else
Return ""
End If
End Function
Click OK and go back to the report
Right-click on the cell you want the expression in and click Expression
Insert the following expression:
=Code.ExtractCode(Fields!Combo.Value, 3)
The value 3 is the "column" that you want to extract from the Combo field, so to get the second "column" you would use 2. If there isn't a column at that position, an empty string is returned.
you could change the visibility of the 3rd column to hidden if the name returns an error
You can append a dummy element and then split:
yourText = "ItemA,ItemB"
item0 = Split(yourText & ",", ",").GetValue(0)
item1 = Split(yourText & ",", ",").GetValue(1)
item2 = Split(yourText & ",", ",").GetValue(2)
item0 = ItemA
item1 = ItemB
item2 =