In SSRS, I am trying to understand the use case of Join and Split.
Lets say we have a multi-value Parameter on the SSRS report.
Assume we also have an embedded SQL or SP that accepts the above parameter (multi-value parameter #ParamName):
SELECT id,name
FROM someTableValuedFunction(#ParamName,',')
In order to be able to pass in the parameter value we should use the foll. expr at the dataset param:
=Join(Parameters!ParamName.Value,",")
This is because the SQL code accepts a single value parameter and Join does exactly that. And similarly the above Join can also be used to display the param value on the report if required.
Or is the JOIN function only needed if we want to display the parameter value on the report? In normal SQL/SP param it sufficient to use Parameters!ParamName.Value ?
Also, when do we use the SPLIT function? Example:
=Split(Parameters!ParamName.Value,",")
Is it that - when the SQL code requires that the parameter value be in form of a table - for example when the SQL is:
WHERE ColumnName IN (#Param)
What about the use case of:
=Split(Join(Parameters!ParamName.Value,","))
Related
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]
I've a tablix with data that comes from a dataset , there is a column called Productgroup and there might be some users that would like to apply a filter on it.
I'm trying to build an ssrs expression that will filter my tablix on that specific column but only when the parameter called #Filter is not null , if null , it does not need to apply filter
I've tried
Expression: Productgroup
Operator: like
Value: =IIF(IsNothing(Parameters!Filter.Value), false, Fields!ProductGroup=Parameters!Filter.Value)
Nothing seems to works :(
First of all, it's best to send your parameters to your dataset and filter on the server, rather than bring back ALL of the data and filter on the client side. So that means parameterizing your stored procedure, or using a WHERE clause to filter the table/view you're connecting to.
If you stick with this approach:
You want your Expression to be "ProductGroup".
You want your Operator to be "=".
You want your Value to be =IIF(IsNothing(Parameters!paramFilter.Value), Fields!Productgroup.Value, Parameters!paramFilter.Value)
What you're doing is saying if the parameter is empty, I need the ProductGroup to be equal to the ProductGroup. That's always true. But if the parameter is not empty, the ProductGroup has to be equal to the parameter value.
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.
Can I use the below expression to pass multiple value in a parameter in subreport?
=Join(LookupSet(1,1,Fields!Name.Value, "DatasetName")," / ")
Will the Join and LookupSet function work in prameter value expression?
No your expression won't work. The Available Values for the Parameter are expecting a single record at a time.
I would create a parameter in the main report with the dataset as DatasetName with the Value of Name. You can set that to Hidden and don't need to use it.
Use that parameter to link to your sub report's parameter.
That should have the same functionality as what you want and would be faster that using the JOIN/LOOKUPSET.
As long as the receiving parameter in the subreport is set to "allow multiple values", you should be able to pass in the lookupset array itself without needing the JOIN function at all.
I have a master that can be filtered using 4 different parameters. I used a iif statement to join all the parameters to filter the report.
The problem I am now having is when more than one paramater is selected, it tends to return values for the first parameter rather than for all
My paramter expression is as follows:
expression
iif(IsNothing(Parameters!Div.Value)=0,Parameters!Div.Value
,iif(isnothing(Parameters!St.Value)=0,Parameters!St.Value
,iif(isnothing(Parameters!Sp.Value)=0,Parameters!Sp.Value
,Parameters!Hc.Value)))
values
=iif(IsNothing(Parameters!Div.Value)=0,Parameters!Div.Value
,iif(isnothing(Parameters!St.Value)=0,Parameters!St.Value
,iif(isnothing(Parameters!Sp.Value)=0,Parameters!Sp.Value
,Parameters!Hc.Value)))
Any help will be helpful
I think what you are trying to do is something like this:
=IIF(NOT ISNOTHING(Parameters!Div.Value), Parameters!Div.Value,
IIF(NOT ISNOTHING(Parameters!St.Value), Parameters!St.Value,
IIF(NOT ISNOTHING(Parameters!Sp.Value), Parameters!Sp.Value,
Parameters!Hc.Value)))
Do you only want to check for one value?
I usually check each parameter separately so it uses all of them at once. Though there may be a situation where your theory is what you want.
If you want to evaluate all the parameters, just add them to the FILTER of the dataset, table, or group. Choose your field in the Expression and the Parameter in the Value.