Setting Parameters from another Parameter In SSRS - reporting-services

I was able to get this working is SSRS 2008, but do to the fact that my company only has 2005 servers I need to downgrade the report to 2005.
The idea is for a given person name there are two key fields EntityType and EntityId
So I have a parameter from a dataset where the Label is the Name and the value is EntityType_EntityId
I use the split function to take the left and right sides of from _
In 2008, I set the query parameters of the dataset to the split function and it works
In 2005, I set the Default Value of each Report Parameters
Now when I run the report and put textboxes showing the value of the parameters, the values are shown correctly but the query does not run. I am guessing that this is a lifecycle issue being
Get Name Parameter
Run Report
THEN Set Parameters = Split of Name
But the problem with that is the second time I run the report I should get result and I do not. Does anyone know what I am doing wrong.
I guess I can pass in the underscore delimted string to the stored procedure and parse it there, but my question is can this be done in the report? Reason being other callers will pass in the parameters as two seperate values.

I already found a suitable answer
Set the query source as text
DECLARE #EntityType INT
DECLARE #EntityId INT
IF #Name = '0_0'
BEGIN
SET #EntityType = NULL
SET #EntityId = NULL
END
ELSE
BEGIN
SET #EntityType = LEFT(#Name,CHARINDEX('_',#Name)-1)
SET #EntityId = RIGHT(#Name,LEN(#Name) - CHARINDEX('_',#Name))
END
EXEC proc #EntityType, #EntityId

Related

SSRS - Parameter(Multi-Value) Passed to Stored Procedure returns last value

I've used the join function to create a string out of an array of variables.
=Join(Parameters!Variable.Value, ",")
Let's say that the expression is using a parameter called Variable to an expression called varstring. As well as to verify that it's working correctly, I created a text box in my report to show me the output of varstring. It looks like this:
123,456,789
Now I'm passing that string as a variable to a stored procedure. The code in the stored procedure would look similar too:
Declare
#var varchar(30) = varstring;
Select * from table where value in (SELECT * FROM string_split(#var, ','))
Lastly, the Variable parameter in SSRS is set to allow multi-values.
When I run this though, my report only returns records associated to the last string split. So in the above it only returns records equal to 789 in the report.
When I hardcode the values into the stored procedure, it returns records where value equals 123,456, and 789.
What am I missing?

Paramter is missing a value in SSRS

I'm calling a Detail report from the summary report and my summary report field is passed as a parameter to the detail report. However when clicking on certain rows based on one condition, the detail report opens correctly.
Certain rows shows the type parameter is missing.
I am passing the type value while invoking the reports and value is passed from the type field in the summary report
Eg IF(#type=''A'')
EXEC AcceptedDetail
If (#type = ''R'')
EXEC AcceptedDetail
In this case R works fine while A does not.
Try
DECLARE #type CHAR(1) = 'R'
IF #type IN ('A','R')
BEGIN
EXEC AcceptedDetail
END

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 report is empty

I'm starting to learn Reporting Services. I did my first report that uses a parameterised stored procedure as a data source. Unfortunately even though the procedure works when called from Management Studio, the report comes up empty. The parameter prompt is there and I entered the value that should work. Is there a way to see what's passed to the SQL server (I'm using VS 2012 PRO with SQL Server 2012 Express, So I don't have the SQL Profiler...)? Is there a way to display errors?
OK I finally figured it out. The stored proc. accepted an optional parameter:
#DealID varchar(15) = ''
I was testing it in the where clause like so:
WHERE (#DealID='') OR (SA.Deal_ID = #DealID)
In the parameter settings of the dataset I specified a default value of "" and set it to accept null values and set it's visibility to hidden.
Turns out that even though there was a default value specified, the #DealID parameter was getting null in it. I only realised it when I commented out the WHERE clause and I finally got the data on the report. I solved it by modifying the WHERE like so:
WHERE (#DealID='' or #DealID is null) OR (SA.Deal_ID = #DealID)

Fields cannot be used in report parameter expression

I have to set the start_date of my report depending of a report parameter. The time stamps are calculated in a database query.
My expression looks like this:
=SWITCH (
Parameters!report_type.Value = 1,First(Fields!daily_start.Value, "Timestamps")
,Parameters!report_type.Value = 2,First(Fields!weekly_start.Value, "Timestamps")
,Parameters!report_type.Value = 3,First(Fields!monthly_start.Value, "Timestamps")
)
Unfortunately I get the error message:
A value expression used for the report parameter 'time_from' refers to a field. Fields cannot be used in report parameter expression
I know, that this is not allowed because SSRS cannot be sure in which order datasets are called. But I think this is not dangerous.
All time stamps are received by query without parameter. The parameter report_type is selected by a user before the report will be generated.
Can someone give me a hint for a workaround?
Here's the workaround - get the value using SQL.
Create a new Dataset called StartDates:
SELECT CASE
WHEN #report_type = 1 THEN daily_start
WHEN #report_type = 2 THEN weekly_start
WHEN #report_type = 3 THEN monthly_start
END AS StartDate
FROM MyTable
You already have the #report_type and #time_from parameters. With the #time_from parameter, set its Default Values to Get values from a query using the StartDates dataset and the Value field StartDate.
Now, you'd think this might be enough to make it work - you're referencing this query as the default value and as you change the #report_type parameter the other parameters refresh, but the first date in the #time_from parameter never changes. That's because the refresh happens on the Available Values query, not on the Default Values query.
So you also need to wire up the Available Values query to the StartDates query. Now your query will fire on the change of #report_type and the default value will be set to the appropriate date for your selection.
I switched from a query to Stored Procedure and was getting this error. Things I tried:
Ensured I had sufficient permission on the database (you need EXEC rights or DBO to run teh sproc)
Delete the existing parameters (and then use refresh fields to refresh/get the correctly named ones back)
Remove the square brackets around the stored procedure if you've specified that
Sometimes, Expressions can get a bit verbose. I have created a Report Code Function and then used that as the Parameter Value.
For example, I created a Code function called "CalculateDateSet" and then set the Report Parameter to this expression:
"=Code.CalculateDateSet(Parameters!Month.Value, Parameters!Year.Value"