Passing values for multi-value parameter in SSRS query string - reporting-services

I have two reports built using SSRS 2005. The first report is set to navigate to the second when a specific field is clicked. I am using an expression similar to the following in the "Jump to URL" property of the textbox:
="javascript:void(window.open('http://server/reportserver?%2fFolder%2fMyReport&rs:Command=Render&Date=" & Fields!Date.Value & "&MachineId=" & Fields!Machine.Value & "'))"
There is a multi-value parameter on the second report. I need to pass multiple values for this parameter in the URL query string when calling this report. Is there a way to pass multiple values for a parameter in the query string of a report? Or can you pass a parameter that will cause the Select All value to be selected?
Thanks.

Just add additional query string parameters.
For example, to pass the parameters
Date: 2009-06-01
MachineID: Machine1, Machine2, Machine3, Machine4
to a report named Folder\MyReport on a server named server, you would use the URL:
http://server/reportserver?%2fFolder%2fMyReport&rs:Command=Render&Date=2009-06-01&MachineId=Machine1&MachineId=Machine2&MachineId=Machine3&MachineId=Machine4

Use join(Parameters!<name>.Value,"&<param_name>=") in the url for multivalued parameters.
If you are passing these parameters into a dataset you need to do a join(Parameters!<param name>.Value) when you pass the parameter in and then use a split function in SQL. This one works well:
ALTER FUNCTION [dbo].[fnSplitParam]
(#RepParam nvarchar(4000), #Delim char(1)= ',')
RETURNS #Values TABLE (Param nvarchar(4000))AS
BEGIN
DECLARE #chrind INT
DECLARE #Piece nvarchar(100)
SELECT #chrind = 1
WHILE #chrind > 0
BEGIN
SELECT #chrind = CHARINDEX(#Delim,#RepParam)
IF #chrind > 0
SELECT #Piece = LEFT(#RepParam,#chrind - 1)
ELSE
SELECT #Piece = #RepParam
INSERT #Values(Param) VALUES(CAST(#Piece AS VARCHAR))
SELECT #RepParam = RIGHT(#RepParam,LEN(#RepParam) - #chrind)
IF LEN(#RepParam) = 0 BREAK
END
RETURN
END
I recommend using the single valued method if the end user does not have to select the parameters directly since it saves you 2 characters per parameter in the url.

I've been trying to do a similar thing to OP, and found putting this &rp:mySelectAllParameter=<ALL> in the url works to select all

Related

How can I pass a returned VARCHAR from a SELECT statement in a stored procedure?

Relevant code:
SELECT `startdate`, `problem`
INTO tktCompletedDate, problem
FROM servicerequest
WHERE (requestID = tktRequestID);
CASE problem
WHEN "Screen is broken" THEN
SET tktProbSpec = 'installed replacement screen';
ELSE SET tktProbSpec = 'Ran Diagnostics';
END CASE;
Trying to complete a class assignment (big surprise) and when I run this SELECT is returns the startdate and passes it into tktCompletedDate variable no problem, but the problem field does not get passed. When I check it later it says the value is NULL.

SpagoBI OLAP report passing optional parameter

Helo. Today is my another fight day with OLAP raport with optional parameter. I have problem with MDX query. I wrote it like this:
select
NON EMPTY {{[Measures].[VALUE]}} ON COLUMNS,
NON EMPTY {
IIF(ISEMPTY([CUSTOMER].[${param}]) //CHECKING IF PARAMETER IS EMPTY
,{[CUSTOMER].[COUNTRY].Members},
{[CUSTOMER].[${param}]}
)
}ON ROWS
from [TRANSACTIONS]
${param} is my optional parameter for [CUSTOMER].[COUNTRY]. I unchecked "required" check button for my parameter, so OLAP should have all [VALUE] after executing it without parameter. And there is a problem, because after launching my OLAP raport parameter probably wants to be filled with something. It gives me an error.
Profile attribute 'param' not existing.
But I dont want to fill it with profile attribute. I have created list of values, and analytical driver for my parameter, which I use to pass possible values to my list box string parameter - ${param}.
Is there possibility to have OLAP report with optional parameter? Any BI master here?
I would be greatfull for any help.
Update: I have done something like this, I think this syntax is right, (I was checking SpagoBI examples)
WITH MEMBER [CUSTOMER].[SELECTED] AS ' Parameter("param") ' , SOLVE_ORDER = 2
MEMBER [CUSTOMER].[LEN] AS ' LEN(Parameter("param")) ', SOLVE_ORDER = 1
select
NON EMPTY {{[Measures].[VALUE]}} ON COLUMNS,
NON EMPTY {
IIF([CUSTOMER].[LEN]=0
,{[CUSTOMER].[COUNTRY].Members},
{[CUSTOMER].[CUSTOMER].[SELECTED]}
)
}ON ROWS
from [TRANSACTIONS]
But now I have same error for both possibilities (set/unset) parameter
javax.servlet.jsp.JspException: org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: com.tonbeller.jpivot.olap.model.OlapException: 1
Any ideas? Thanks :)
This question is a direct copy oF your previous posts:
https://stackoverflow.com/questions/38970610/olap-report-with-optional-parameter
Is ${param} is a string?
If it is a string then the following should function:
WITH MEMBER [Measures].[x] AS ${param}
SELECT
NON EMPTY {[Measures].[x]} ON COLUMNS
FROM [TRANSACTIONS];
Does it function?
If it does not function then the question is not really mdx related - as for some reason your syntax or the way the parameter is moving to the client is wrong.
note
The above is the equivalent of this super simple script:
WITH
MEMBER [Measures].[x] AS "hello world"
SELECT
NON EMPTY
{[Measures].[x]} ON 0
FROM [Adventure Works];
Do you have AdvWrks cube? Try these:
WITH
MEMBER [Measures].[x] AS "I'm not empty"
SELECT
{
IIF
(
(IsEmpty([Measures].[x])) //<< this returns False
,[Product].[Product Categories].[Category].MEMBERS
,{[Measures].[x]} //<< this is what IIF returns
)
} ON 0
FROM [Adventure Works];
It returns this:
Now I tested out IsEmpty:
WITH
MEMBER [Measures].[x] AS "I'm not empty"
SELECT
{
IIF
(
(NOT //<< added this to check functionality of IsEmpty
IsEmpty([Measures].[x]))
,[Product].[Product Categories].[Category].MEMBERS //<< this is what IIF returns
,{[Measures].[x]}
)
} ON 0
FROM [Adventure Works];
We get the following:
What I think is happening in your scenario is this - the param is not empty but is actually a zero length string:
WITH
MEMBER [Measures].[x] AS ""
SELECT
{
IIF
(
(
IsEmpty([Measures].[x]))
,[Product].[Product Categories].[Category].MEMBERS
,{[Measures].[x]} //<< the zero length string goes to here
)
} ON 0
FROM [Adventure Works];
Results in:

Multi-value parameters in ssrs

I have a multi-value parameter. how I get one by one values from this parameter.
value=new_index and label=new_french
and want to insert these values into these labels
You can access the individually selected multi-value parameters by their index (the index is zero-based). So if you want the first selected parameter value (for example, to put it into a label), you can address it like so:
=Parameters!MyParameter.Value(0)
You could access them all using custom code:
Function DoSomething (ByVal parameter As Parameter) AS String
Dim Result As String
If parameter.IsMultiValue then
For i As integer = 0 To parameter.Count-1
Result = Result + CStr(parameter.Value(i)) + ", "
Next
Result = Left(Result, Result.Length - 2)
Else
Result = CStr(parameter.Value)
End If
Return Result
End Function
then use this expression to access the result:
=Code.DoSomething(Parameters!MyParameter)
Note that you are passing the parameter object here, not the Value property. We access the Value property in the custom code function.

How to determine if a parameter value was passed to a stored procedure

I want to create a stored procedure (in SQL Server 2008 R2) that will update a record in a table based on the table's PK.
The stored proc will have, for example, four parameters:
#ID int,
#Name nvarchar(50),
#Email nvarchar(80),
#Phone nvarchar(20)
How can I determine if the caller of the stored proc passes a NULL value for one (or more) of the parameters vs. if the caller didn't pass anything for one (or more) of the parameters?
C# caller example:
Caller specifies NULL for #Phone:
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "EditPerson";
cmd.Parameters.AddWithValue("#ID", id);
cmd.Parameters.AddWithValue("#Name", 'Frank');
cmd.Parameters.AddWithValue("#Email", 'frank#frank.com');
cmd.Parameters.AddWithValue("#Phone", DBNull.Value);
DatabaseManager.instance.ExecuteScalarQuery(cmd);
}
Caller ignores the #Phone parameter:
using (SqlCommand cmd = new SqlCommand())
{
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandText = "EditPerson";
cmd.Parameters.AddWithValue("#ID", id);
cmd.Parameters.AddWithValue("#Name", 'Frank');
cmd.Parameters.AddWithValue("#Email", 'frank#frank.com');
DatabaseManager.instance.ExecuteScalarQuery(cmd);
}
What I'm trying to accomplish here is, if the caller explicitly specifies a NULL value for a parameter, then I will update the record with a NULL value. However, if the user explicitly ignores passing a parameter, then the UPDATE query will retain the value of the field/column that is already set for the particular record (i.e. the query will NOT update that particular column).
I suppose that I could specify default values that can be safely assumed that a caller will never use - something like this:
#ID int,
#Name nvarchar(50) = 'NameIsUndefined',
#Email nvarchar(80) = 'EmailIsUndefined',
#Phone nvarchar(20) = 'PhoneIsUndefined'
Then, in the stored proc, I can check for the undefined values - if the parameter vars are still set to the NameIsUndefined, EmailIsUndefined, and/or PhoneIsUndefined values, then I can safely assume that the caller did not explicitly define values for those params. Is this the only way to accomplish my goal?
If you declare your parameters like this (without default value), the stored proc will require all four of them and will just fail if any of them will not be passed to the EXEC statement composed by the provider.
You may declare some of the parameters optional like this:
#Phone nvarchar(20) = NULL
however, there will be no way to tell inside the sproc if it was omitted or explicitly set to NULL.
There's no way to tell the difference between NULL and NULL in SQL Server, AFAIK.
In your C# code, I would A) Pass another value, like an empty string, to indicate an empty value was passed, then process that in SQL to write NULL to the DB if the value was passed, or retain the previous value if the variable is NULL, or B) Instead of passing DBNull.Value, pass the previous value that was read from the DB.

Display Parameter(Multi-value) in Report

Can anyone tell me how to display all the selected value of my multi value parameter in SSRS report. When giving parameter.value option it gives error.
You can use the "Join" function to create a single string out of the array of labels, like this:
=Join(Parameters!Product.Label, ",")
=Join(Parameters!Product.Label, vbcrfl) for new line
I didn't know about the join function - Nice! I had written a function that I placed in the code section (report properties->code tab:
Public Function ShowParmValues(ByVal parm as Parameter) as string
Dim s as String
For i as integer = 0 to parm.Count-1
s &= CStr(parm.value(i)) & IIF( i < parm.Count-1, ", ","")
Next
Return s
End Function
Hopefully someone else finds this useful:
Using the Join is the best way to use a multi-value parameter. But what if you want to have an efficient 'Select All'? If there are 100s+ then the query will be very inefficient.
To solve this instead of using a SQL Query as is, change it to using an expression (click the Fx button top right) then build your query something like this (speech marks are necessary):
= "Select * from tProducts Where 1 = 1 "
IIF(Parameters!ProductID.Value(0)=-1,Nothing," And ProductID In (" & Join(Parameters!ProductID.Value,"','") & ")")
In your Parameter do the following:
SELECT -1 As ProductID, 'All' as ProductName Union All
Select
tProducts.ProductID,tProducts.ProductName
FROM
tProducts
By building the query as an expression means you can make the SQL Statement more efficient but also handle the difficulty SQL Server has with handling values in an 'In' statement.