I want to display all values of a numeric column as a default value in a numeric parameter. With non-numeric/text column, I have used select 'All' and it is selecting all values of that column. But select 'all' or select '%' or select '%[0-9]%' is giving me error in numeric column. I don't want to use "allow multiple values' option Can anyone help me.
I expect parameter to populate all numeric values by itself.
one way to do this for numeric parameters without multi values is to do a union all your parameter value with a -1 and call it select all.
So if your parameter (#numcolumn) values were like this
1
2
3
then you simply append a -1 using the union all
like this. (varchar(5) is just a choice to show example.. choose something that suits your needs)
select -1 as value
,'Select All' as value_name
union all
select mycolumn as value
,cast(mycolumn as varchar(5)) as value_name
from mytable
so now your #numcolumn parameter list will be like this
value value_name
-1 select All
1 1
2 2
3 3
Then in your where clause for your dataset, you set your parameter value like this.
where ( #numcolumn = -1 or sometable.somecolumn = #numcolumn)
so if you select -1 as your parameter value, then the query will return everything.. else it will filter by the selected value from the parameter.
To make the parameter selection look tidy.. set the #numcolumn parameter value to value and parameter label to value_name
Hope that made sense!
Related
I have the next report…
I wanted to add a parameter… Which would be user entered… The thing is that, if the parameter is empty, I want it not to filter anything… and if populated, to filter by that…
Can this be achieved? I reckon that if empty will do
WHERE PARAMETER = ‘’
and of course that’s not the intended behavior…
You can have a dummy value in your selection list.
For example:
select
'All' as [Label],
null as [Value]
union all
select
a.Name as [Label],
a.Value as [Value]
from dbo.HereAreMyValues as [a]
This will give you a selection option of "All" to show all (i.e. no filtering) in your parameter.
You can then reference this as..
from dbo.Data as [d]
where (d.Value = (#Parameter) or (#Parameter) is null)
This will give you the data that either matches the parameter value, or all if the parameter value is null.
I have an ssrs report, in which the user can choose the type of the chart he needs(pie,line,.., table).if the user chooses "table", another parameter must be chosen (#ListOfColumns). if I choose "table", I can see the list of fields and generate the report. When I choose another type of chart, the list of fields is empty(as it should be),but cannot generate the report due to "#ListOfColumns" parameter needs a value.I tried to set this parameter to blank and null, but didn't work. before adding "table" and cascading parameter, everything was working fine.
detail:
#ChooseChartType parameter is integer, with "specify values":1,2,3,4(4 is table).
#ListOfColumns dataset is:
if(#ChooseChartType=4)
SELECT 1 ID, 'TypeOfTest' AS ColumnName UNION
SELECT 2 ID, 'NoOfTest' AS ColumnName UNION
SELECT 3 ID, 'Priority' AS ColumnName UNION
SELECT 4 ID, 'Purpose' AS ColumnName UNION
SELECT 5 ID, 'TypeOfRoute' AS ColumnName UNION
SELECT 6 ID, 'CreatedBy' AS ColumnName
Add IF conditions to your dataset then just remove #ListOfColumns from your dataset script if it's not needed.
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".
I've set up a report with a multi-valued parameter. The dataset is essentially
select 'Abc' as field1
Union all
select 'lmnop'
union all
select 'xyz'
order by Field1
Available values - Label and Value are both set to Field1
Default values - Value is set to Field1
I would expect only the 'Abc' to be selected by default and the rest unselected. But instead, I'm seeing all of them selected. This works as expected with single valued parameters.
SSRS 2008 R2
Based on this answer and some quick testing, it seems that when a parameter is defined as multi-value and there is no NULL in the dataset, the default behaviour is to select all of them. Otherwise, it selects None. Select All as default value for Multivalue parameter
Which makes sense, I suppose, from a behaviour perspective. You're allowing multi-select so why not assume someone will start with everything selected? Seems as arbitrary as expecting the first thing to be selected.
Got it, whatever is returned from the default values dataset will become selected when the report is run.
So if I have as Dataset for Available option
select 'a' as field1
union all
select 'b'
union all
select 'c'
and I have as Dataset2 for Default option
Select 'b' as selectedField
Then, only 'B' will be selected by default when the report is run. Makes sense.