Using a Flag parameter to populate SSRS report - reporting-services

I have a report that must be populated with data based on a #Flag parameter. The report is pulling from one stored procedure which calls data from 2 separate tables. For instance, EQ.Equipment, EQ.Address, EQ.City, EQ.State,... and FL.Equipment, FL.Address, FL.City, FL.State,...
I have added a Flag parameter that if #Flag = 'E' it will pull from the EQ SELECT statement and if #Flag = 'F' it will pull from the FL SELECT statement. Is this possible? If so, how can I implement this?

Try something like this (using the actual name of the tables):
IF (#PARAM = 'E')
BEGIN
select * from EQ_table
END
ELSE
select * from FL_table
In the dataset properties map #PARAM to the parameter created in your report.
Let me know if this helps you.

Related

Using SSRS report to pass multiple string parameter with single quotes

I am failing to pass parameter value to data set using ,
=split(Parameters!Status.Value,",")
Parameter (#status)defult values -> C,P
Returns Error:
The value expression for the quer parameter '#status' contins ans error: Conversion from type 'Object()'to type 'String' is not valid.
As it looks that the parameter is already a string, what you need to convert it into list is a join function:
=join(Parameters!Status.Value,",")
once you pass the comma separated list to SQL you may need to search the list as discussed here:
SSRS selecting results based on comma delimited list
You could do this the way you want but I would approach this differently as it's easier to see what's going on especially if this gets passed to somebody else to debug later.
There are two ways of doing this. The first is to pass in a single value for Close or Open and then add some logic to the dataset
DECLARE #s TABLE(status char(10))
IF #states = 0 -- Closed
BEGIN
INSERT INTO #s VALUES('c'),('p')
END
ELSE
BEGIN
INSERT INTO #s VALUES('o')
END
select * from myTable a
JOIN #s s on a.status = s.status
I realise it's more code but it's simple to follow.
IF THIS WORKS FOR YOU STOP READING NOW !!
The second option (assuming you don't want your users to just be able to select 'c' or 'p' individually) it a bit more effort to set up only the SSRS side but the SQL is very simple. Don't be put off by the length of the answer it actually pretty simple.
Your dataset query would just look something like this...
select * from myTable a WHERE a.Status in (#status)
In your report design set the #states parameter available values to c, p and o as separate items and make the parameter multi-value.
At this point you should be able to test that the report works and you can select 1, 2 or all three options and get the relevant results, there is no need for joins splits or anything else, it will just work.
Now, as I assume you don't want your users to be able to choose at this level, we need to make some changes.
First add a new dataset called say dsDefaultStatus and set the query to something like
DECLARE #s TABLE(status char(10))
IF #status = 0 -- Closed
BEGIN
INSERT INTO #s VALUES('c'),('p')
END
ELSE
BEGIN
INSERT INTO #s VALUES('o')
END
SELECT * FROM #s
You should new have a new #status parameter. Give this two available labels/values such as 'Close'=0 and 'Open'=1 to match the query above.
Now go back to the #states parameter and change the default values to dsDefaultStatus, you can then hide this parameter if required.
As the user selects the Open/Close status in the first parameter, the defaults selection for this hidden parameter will change. When you run the report the values from the hidden parameter get passed to the report.

How to make drop down parameter in crystal reports

I have certain parameters in the crystal reports which would be passed directly into Stored procedure in sql . Parameter A has 5 values and I want to enable them for users so that when user opens up the report , he is able to select any number of parameters values in the drop down based on which report data would be filtered.
Please advise
For a parameter to select multiple values you need to enable the option allow multiple values to true.
As I know, in designing a report in Crystal Reports you can use a simple SELECT like this:
SELECT CAST(0 AS int) AS Id, CAST(0 AS varchar(0)) As Name
That will give you two fields like Id, Name and you can use them in your report.
Now, you can use that type of SELECT statement instead of running a stored procedure like EXEC SP1 #P1 = P1, #P2 = P2 just inside of your report designer and running that stored procedure when you are filling the Data-Set of your report.

How to handle a parameter that has no value in SSRS

I have a report that has two datasets in it. The first dataset is used to populate a parameter to a second dataset. Everything works fine until the first dataset has no values, whereupon I get a parameter X is missing a value message.
Is there a way to get around this?
Assuming you're using Cascading Parameters, you can use a query similar to the following to populate the second parameter's DataSet:
if exists (select 1 from Param2 where paramVal = #Param1)
begin
select paramVal, paramDetail
from Param2
where paramVal = #Param1
end
else
begin
select paramVal = 'None', paramDetail = 'None'
end
This is just a workaround using an if...else construct to return a dummy row if there aren't any other rows to return - that way you'll always get at least one row returned even if there are no matches for the first parameter value.
You can handle these dummy rows as required later in the report.
As above this is a workaround to address your specific issue, but hopefully will be of some help.
Added after comment:
I just tested now - it works just the same with multi-valued parameters; just change =#Param1 to in (#Param1).
If there are one or more matches in the second DataSet it returns those rows, otherwise just the dummy row.
I did need to shut/reopen the report in VS, but that could have been unrelated.

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"

SSRS Report Builder, is there a way to show values in filter?

Is there anyway to show the user what values are in each field so they can filter on these values?
How is the user supposed to know what values they want to filter if they can't see the values?
If I correctly understand what you are asking:
1) Set up a data set to retrieve the available values for your filter
SELECT DISTINCT MyFieldValue FROM MyTable
2) Create an SSRS parameter which will be used for the user to select a filter. Set it up to allow multiple values, and set the available values to use the data set created in step 1. Let's call this Step2Parameter.
3) Create your core data set for the report, and use the parameter from step 2.
Select MyID, MyFieldValue, Name, Blah FROM MyTable WHERE MyFieldValue in ( #Step2Parameter )
You can repeat this with multiple fields.
Does that get you in the right direction?
Also, make sure that in the Parameter Properties (right click your parameter and select Parameter Properties), that "Select Parameter Visibility" in the "General" menu is set to "Visible".