How do I use different queries based on parameter value - reporting-services

(1).In my ssrs report I have 2 queries which i need to put in my dataset.
Based on a dropdown parameter I want to select which query to run.
Is it Possible to do so? Please, help me out.
Ex.
I
If (Parameters!sFlag.Value == "0")
{ Query1}
else
{Query2}
(2).Also based on same parameter i want to select fields in a textbox.
Ex.
=I
If(Fields!IsFlag.Value="0" , Fields!Field3.Value, Fields!Field18.Value)
I am using Informix .
I searched a lot but couldnt find anything appropriate as this thing I have done with sql query but when I apply the same with Informix it doesnt work.

Assuming both queries return the same fields and use the same connection then you could union them together using the parameter to control which returns data. I know that the MSSQL optimiser will effectively not bother running the non true half of the query, not sure about Informix. The result is that you get the values from the first query when the sFlag parameter is "0" and from the second query when its "1".
SELECT 1 as Value WHERE #sFlag = “0”
UNION ALL
SELECT 2 as Value WHERE #sFlag = “1”

Related

SSRS Multi-Value Parameter - When Select ALL, returns zero rows

My current definitions for this report are like this:
DataSet A = a pretty extensive query with 'AND ai.Channel IN (#ChannelParameter)'
DataSet B = Channel 'Select distinct channel from Account_Info'
result set 'Retail Channel' or 'Wholesale'
Parameter = #ChannelParameter is set to Allow Multiple Values and is Getting the values from Query.
Tablix Properties - Filters
Expression [Channel]
Operator IN
Value =Parameters!ChannelParameter.Value(0)
When I run the report and select 'Retail Channel', I get the correct data.
When I run the report and select 'Wholesale', I get the correct data.
When I run the report and select both values, I get zero rows returned.
When I modify the query for DataSet A to be ai.Channel IN ('Retail Channel','Wholesale'), I get all of the rows. There are no rows in the data where the Channel field is NULL.
I've seen and tried some changes to the expression in the parameter using a JOIN statement, but no better results there.
What am I missing?
You filter expression is incorrect, as you stated (0) that means only the first parameter value will be used.
Having said that, it looks like you are already filtering the data in your A dataset so there is no need for the tablix filter, just remove it.

SSRS 2008 :Is it possible to specify an entire where clause within parameter?

I have a table that I am building a report for. There are about 10 fields, but 4 of those fields may contain value(s) that users would want to filter the report by.
I was thinking I could create a parameter with a list of label/value pairs and the value portion of the parameter item would be an actual where clause for the underlying dataset like:
#filter
label/value
exceptions/where error_field like '%exception%'
counts/where count_field > 100
2016/where year_field = 2016
I tried dataset:
select error_field, count_field, year_field from mytable
#filter
I also tried(leaving where out of parameter value):
select error_field, count_field, year_field from mytable
where #filter
Both dataset queries failed to save. I am thinking I could include all the varying where clauses inside the dataset query statement, but it may require different parameters but how can they be empty unless I used 1=1 as default value. I only wanted to use a single parameter tho.
Any other ideas?
Thank you.
Your dataset query needs to be valid SQL. You can use an expression for the dataset, and work with the SSRS expression language to generate the SQL you need.
Something like:
="SELECT * FROM TABLE " + IIF(Value = True," WHERE 'A' = 'B'","")
However, I think they are a pain to work with. They are harder to understand, and take longer to maintain, and much easier to contain a mistake.
I find it easer and safer just to pass the parameters to a SQL Stored Procedure on the server, especially if you are using a TEXT BOX entry field.

MS Access query based on filtered query

I'm trying to use a query (query2) based on another query (query1).
On a form where both are displayed, I use VBA to add filters for query1. This works for query1, but query2 keeps using the unfiltered query1 as its source no matter what I try. Any suggestions welcome
Many thanks
Two ways to approach this:
Approach 1: in Query2 set Filter on Load to 'Yes', then have your VBA add the filter clause to Query2 and re-run it. So, if you want to filter Query1 based on column [foo] having the value "bar", your VBA would add this to the Filter property of Query2:
Query1.[foo] = "bar"
Approach 2: Parameterize Query 1 - have it use a WHERE clause that points to a control on the form (perhaps a hidden text control if you don't want users to see it). The structure of your VBA would then:
1. change the value of the hidden control
2. Requery Query 1, which will now use the new parameter value
3. Requery Query 2, which will be based on the values of Query 1 (which points to the hidden control).

How to implement Having Clause in SSRS

I'm New to SSRS.
Im trying to create a report where i need to group by [DATA Flag] column which is working fine ,but once the data is grouped i need to set the DATA FLAG ="TotalCancellations" and there is another column CancellDays which i need to set it as <120 .
I tried
Option 1:-
So to achieve this i have added TWO filters one with
Expression : DATA FLAG
Operator =
and Value as TotalCancellations
and the other filter as follows
Expression : Cancelldays
Operator =
and Value as < 120
But its not working and giving empty result,i have records with Cancelldays <120
Option 2 :-
Right click on Group and in General Tab ,Group on Expression as below ]
Fields!DFlag.Value = "TotalCancellations" AND Fields!DFlag.Value <120
which didnt work :(
this is similar to writing having clause in SQL i believe but im not getting how to implement that here in SSRS.
i can add in SQL Query but its already a huge query with lot of unions so please suggest me if there is any way i can implement here in SSRS
Im using Matrix in SSRS 2008
Adjusting the syntax for your option 1 is probably the easiest solution. In the Group Properties, under the Filters section, enter these two filters:
Expression: [DFlag] (Text)
Operator: =
Value = TotalCancellations
Expression: =Sum(Fields!CancelDays.Value) [enter this in the expression builder] (Integer)
Operator: <
Value: 120
Putting all the filters in a single expression, like your option 2, can be useful if you need to filter by one criteria OR another.
Below are the filer expressions
and this is how group by is
The filter should be implemented at the tablix level, not at the group level.

SSRS Report - Dataset Filters

I've written a report for SSRS and Im using dataset filters with expressions to filter the report info. I seem to either have this expression wrong or the filter is not working correctly:
=IIf(Parameters!DoctorID.Value = "All" Or Parameters!DoctorID.Value = "", "*", Parameters!DoctorID.Value)
What I want to accomplish with the above code is if DoctorID = ALL or "" (blank) then I want to omit it from the filters so I return information for all doctors. However, whenever the value of DoctorID = ALL, I'm returning no rows what so ever. It should be the case that i'm getting ALL rows since DoctorID is not a specific number.
Does the "*" (star) not denote an omitting of that filter? Am I doing something wrong here?
Thanks!
The filter formula you provide is only half the equation: what is the operator and what are you comparing this to? And yes, I haven't seen SSRS use asterisk as a wildcard.
Consider putting your filter into the query for the dataset. The SQL WHERE clause can get pretty powerful. I would write your filter into the query as
...
WHERE
#DoctorID = 'All' OR #DoctorID = ''
OR #DoctorID = myTable.DoctorID
This will also let you move to a multiple value parameter pretty easily.