I have 2 report parameters as customerNumber and customerName. The user must enter one or the other - Not both, so text entered on the
first one will disabled the second parameter and vice versa.
Can this be done using dataset or how to link both so as only 1 of them accept values?
Many thanks
I don't 'think' you will be able to do this.
You can simulate one being disabled based on the other but you will only be able to do that one way I think otherwise you would have a circular reference.
Imagine your customerName dataset looked something like
IF #customerNumber IS NULL
BEGIN
SELECT '' as customerName
END
ELSE
BEGIN
SELECT DSITINCT customerName from myTable
END
This would be OK, but you could not then do the same to the customerNumber parameter's dataset as it would have to reference the customerNumber parameter, and round we go again.
Other option?
Assuming you want the user to supply a name or number but not both, you could use a single field for name/number entry and then a list based on that that contains the actual value you want.
So the first parameter customerSearch is plain text single value.
The dataset for the second parameter 'customerNumber` available values might look like this
SELECT customerName, customerID
FROM myTable t
WHERE customerName LIKE '%' + #customerSearch + '%'
OR customerID = #customerSearch -- CAST the parameter if required
Set the parameter to multi-value and optionally set the default values to the same dataset.
Not ideal but maybe a reasonable compromise.
Related
I created a report on VS Report Builder from a query I wrote on SQL Server 2014.
The Report has two parameters:
The date the report should run for.
The agent to exclude from the report.
The query has conditions for the date and where agent NOT IN (agents selected from the drop-down)
Sometimes, there are no agents to exclude. Hence, the report should run even when there are no agents selected.
The report runs fine when there is at least 1 agent selected. But doesn't run at all when no agents are selected. Gives me an error message, "Please select value for the parameter 'Select Agent' ".
In Parameter properties, I have selected 'Text' as Data type. I have also checked 'Allow blank value("")' and 'Allow Multiple values'.
In the Available Values tab, I have selected 'Get values from a query' because I have a separate dataset that pulls records of the agent names from a separate table.
In Default Values tab, I have selected No Default Value. Maybe, I should select 'Specify Values' instead. But what should I specify the value as? Because, when I selected 'Specify values' and added a (Null) value, I got an error message that says 'A null default value was specified for the parameter but the parameter does not allow null values.' I even tried specifying an obscure '1111111' as the default value. Still got the error message to select an agent.
A good way to handle this is to add an option to your Available Values that can be used to skip that parameter. You would add it by using a Union All in the query that the parameter is being populated from. For the label you could use something like "N/A" and the value can be NULL. This way, you will be able to specify it as a Default Value and users will be able to select it when there are no appropriate real values. Finally, it sounds like you may have already done this, but make sure your query will handle the parameter being NULL and still give you the correct results.
EDIT:
SELECT AgentID, AgentName
FROM (
SELECT DISTINCT AgentID, AgentFirstName + ' ' + AgentLastName [AgentName]
FROM AgentStats
WHERE MidnightStartDate >= dateadd(day, -60, getdate()) AND MidnightStartDate < getdate()
UNION ALL
SELECT 'N/A', NULL
) A
ORDER BY AgentName
The union adds the NULL value to the results. This is all wrapped in a subquery so that you can still use the ORDER BY clause.
I have a question regarding to show more than one value to drop down but use only one value as a parameter
My query
select custcode, custname from customertable
in return i will have two columns.. at SSRS i want a single dropdown which will show me these two data, but once user select a value, it should pass only customer code to parameter, how to do that with SSRS
Parameters have two properties that are important - the Value and the Label. The Value is used as the parameter value in things like SQL expressions; the Label is what is displayed in the parameter selection box.
So we need to have two fields returned by our parameter lookup query in Available Values: the custcode which is used as the Value field and the concatenation of custcode and custname for the Label field.
select custcode, custcode + ' - ' + custname as Label
from custmertable
I have a list of 10 places that I put them as values in my SQL reporter 2012.
In my report I am counting the number of clients based on the selected place.
What I want is to have the total of clients in all places in case no value was selected by default.
You need to edit your query/datasource to account for when the null value is selected by user.
In your available values you need to put an entry for Null values as Value and All Places as Label. when the user selects the All places (internally Null) you can pass that into your query.
Your where clause would look something like this:
Where ...
AND (Place = #Place Or #Place is Null)
I'm creating a debtor invoicing report which has two parameters.
Parameter 1: This is a single value parameter called #booking_date. I filter the results(main dataset) by adding this into the query as a query parameter.
Eg. WHERE BookingDate = #booking_Date
Parameter 2: This parameter has two specified values - Yes or No. The parameter is called #live_run and the default value is 'No'. Basically, when this parameter has the default value of 'No', it does not limit/effect the results in any way. On the other hand, when this parameter has a value of 'Yes', it should limit the results by only displaying the bookings where the invoice has been paid off. There is a field I can use for this called Booking_Paid_off as follows - WHERE Booking_Paid_Off = 1.
I have parameter 1 in place, but I am unsure how to bring in Parameter 2 because it will be based on two conditions, do I need to use an If statement or a case statement? Do I need to create a new dataset for the second Parameter? I only want to limit the results with Parameter 2 ONLY if Parameter 2 has a value of Yes, otherwise I want the results to stay the same.
You have many options. You can switch out the Dataset entirely based on the parameter or use an IF inside the dataset to determine which query to run or simply check the parameter in your WHERE clause.
I recommend the latter.
SELECT
Field1,
Field2
FROM
Table1
WHERE
(
(#live_run = 'Yes' and Booking_Paid_Off = 1)
or (#live_run <> 'Yes')
)
We have a series of reports which return a set of values for a parameter based on the userID. This works and we're happy with the way it works.
Now we need to implement a default parameter setting. The logic being
If there is only one value in the parameters available dataset, then set that as the default.
If there is more than one value in the parameters available dataset, then leave the parameter blank.
This is what I have so far - I know I have the following issues:
-Parameters cannot read fields, therefore I need the expression to look at the dataset as a whole.
-I'm unsure what my then statement should be to allow the user to review all available values without them being selected.
=IIf(CountDistinct(Fields!storekey.Value, "UserStoreVerification")) = 1, First(Fields!storekey.Value, "UserStoreVerification")," ")
You can create a separate dataset to populate the "default values" for the parameter. In this dataset you can add logic to count the number of rows that would be returned by the other dataset that provides the parameter values. If there are greater than 1 values returned by the first query then the second dataset just returns NULL (i.e. no default values are selected).
Example
If your original dataset for parameter values (e.g. "dsParamProduct") used a query like this:
SELECT ProductNumber
FROM dbo.Product
WHERE Available = 'Yes'
Then the dataset query for the default values (e.g. "dsParamProductDefault") could be something like this:
DECLARE #ValueCount INT
SELECT #ValueCount = COUNT(*)
FROM
(
SELECT ProductNumber
FROM dbo.Product
WHERE Available = 'Yes'
) vals
IF #ValueCount = 1
SELECT ProductNumber
FROM dbo.Product
WHERE Available = 'Yes'
ELSE
SELECT NULL
Supplying "NULL" as the default value when there is more than one value will mean none of the available values are selected and therefore the user will have to manually select them (assuming that NULL isn't a valid value for your parameter - if it is then make sure the default query will return something else that is definitely not valid). If there is only one possible value then the default value query just returns the same result as the parameter values dataset, which means that the parameter value will be selected.
Set up another parameter that is dependent on the first, same type but slightly different name, and do your code at bottom with one suggested change:. Change " " at the end before the parenthese end to be 'NOTHING' instead. I believe this is interpreted by SQL as NULL which is what you want.
Now you should be getting population of the parameter so I would debug and check it by just dragging and dropping it to the design surface and it should be black if you have more than one default value. You can optionally make this parameter 'hidden' once you can confirm it works.
Now you trick your main dataset with a nifty predicate (or else use some other logic if it suits you better)
Where value = isnull(#DependentParam, value)
Basically this is stating "if the parameter is not null use it, else equate the clause to be everything as it will assume value = value".