ORA 01797- operator must be followed by any or all - reporting-services

I am testing a condition like this in the where clause of a subquery. But I am getting the error "operator must be followed by any or all" when I execute the SSRS report.
dbase is oracle. And i need to use IN with parameter because the parameter in SSRS report is multivalued. I am using a separate function to generate dates that go in :P_Date.
I need to check if this date is = or < or null . All three conditions need to be tested.
where
trunc(tt.fyh_fecha) IN (:P_Date) OR
trunc(tt.fyh_fecha) <(:P_Date) OR
trunc(tt.fyh_fecha) IS NULL AND
tc.cod_tree = 'blue' AND
tt.color_flower = 'pink'

This doesnt seem directly possible - you are trying to use a parameter containing an array of values against the < operator which only expects one value. Your design doesnt make any logical sense to me either (<= multiple dates?), but anyway ...
I would add a join to a Calendar / Date Dimension table, where I would apply the IN (:P_Date) criteria to get a list of Date values as a deliberate cross join.
Then I would replace:
trunc(tt.fyh_fecha) IN (:P_Date) OR
trunc(tt.fyh_fecha) <(:P_Date) OR
with:
trunc(tt.fyh_fecha) <= Dim_Date.Date_Value

Related

how to capture grater than symbol parameter to build date field comparison in where clause for SSRS parameter report

new to SSRS report design. Although, I've used CASE statement before but not sure how to utilize in a condition where SSRS report needs to two parameters ( parameter symbol (>,<,=,%) and parameter date ) pull data from a dataset.
I'm wondering if CASE statement can be used to achieve this need?
Or any other suggestion that would work for this condition, will be greatly appreciated.
PS: I've not come across such example so far
I'm assuming that you want to parameterise the actual operator so the user can for example, choose < 1000 or > 50 etc...
If that's correct then you can do this as follows.
Assume we have two parameters
pOperator which has values of ">", "<" and "=" (note for the = option you will need to specify this as an expression ="=" or SSRS will think you have a blank expression.
pMyValue which will allow the users to type a number in
What you need to do is change the dataset query to be an expression, so something like this.
="SELECT Employee, Salary FROM myTable
WHERE Salary " & Parameters!pOperator.Value & " " & Parameters!pMyValue.Value
If you had used > and 30000 as your parameter values then this would return
SELECT Employee, Salary FROM myTable
WHERE Salary > 1000
You could also have a single parameter where the user can type the whole ">=15000" and then just replace the two parameters above with a single one.

Group projects by Fiscal Year Date expression based on one field value, if field value is null then group projects based on another field value

I am running a report where the projects are grouped by FY based on Fields!EstSubstantial_Completion.Value. Expression below:
=IIf(Month(Fields!EstSubstantial_Completion.Value)=10,
year(Fields!EstSubstantial_Completion.Value)+1,
IIf(Month(Fields!EstSubstantial_Completion.Value)=11,
year(Fields!EstSubstantial_Completion.Value)+1,
IIf(Month(Fields!EstSubstantial_Completion.Value)=12,
year(Fields!EstSubstantial_Completion.Value)+1,
year(Fields!EstSubstantial_Completion.Value))))
The expression is working, but my supervisor would like the projects to first be grouped into a FY based on another date field Fields!Savings_Report_Date.Value first and then if the field is blank (null) reference the Fields!EstSubtantial_Completion.Value field as the date to determine FY grouping.
I am new to SSRS reports so I am unsure if there is a way to write this type of expression.
Thanks!
The easiest way to do this would be to add a calculated field to your dataset.
Go to the dataset properties, then the "Fields" tab, then add a new field, select calculated when prompted.
Give the field a name such as FYCalc and set the expression to
=IIF(Fields!Savings_Report_Date.Value = Nothing, Fields!EstSubtantial_Completion.Value, Fields!Savings_Report_Date.Value)
Now all you need to do is swap out Fields!EstSubtantial_Completion.Value in your current expression and use Fields!FYCalc.Value instead.
Optional :
When you have nested IIF statements, it's often easier to use the SWITCH function instead. It's much easier to read.
=SWITCH(
Month(Fields!FYCalc.Value)=10, year(Fields!FYCalc.Value)+1,
Month(Fields!FYCalc.Value)=11, year(Fields!FYCalc.Value)+1,
Month(Fields!FYCalc.Value)=12, year(Fields!FYCalc.Value)+1,
True, year(Fields!FYCalc.Value)
)
The final True acts like an Else
You could simplify this further like this
=IIF(
Month(Fields!FYCalc.Value) >= 10 and Month(Fields!FYCalc.Value) <= 12, year(Fields!FYCalc.Value)+1,
, year(Fields!FYCalc.Value)
)

Filtering out results based on length of reference number

I have a report, in report builder, where I am getting duplicate rows based on the reference number.
In the below example, is there anyway that I can remove any reference number that is longer than 9 digits using an expression, I've looked into using LEN but cant seem to make it work for me! I am very new to SQL and report builder.
You can use a Filter on either the Dataset or the object (table, chart...).
The Filter Expression would be the LEN of you field - =LEN(Fields!HB-RENT-REF.Value)
The Type would be Integer.
The Operator would be <=.
And the Value would be 9.
This would only allow records with a HB-RENT-REF field length of 9 or less.
MS Docs: Dataset Filter
If you're using SQL scripts or procs to build your report, then you could simply include a WHERE clause that checks for if the length of your column, using the LEN() method, is less than or equal to your condition. So something along these lines:
SELECT *
FROM YourTable AS yt
WHERE LEN(yt.YourColumn) <= 9;
You will want to replace the * with the specific columns you want and use the appropriate tables too of course. But that's the general idea of checking for length in a WHERE.

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 Expression in field using IN

I am trying to filter the data returned in a field using multi-value parameters. I need to filter based on 3 conditions:
--Before a Warranty End Date
--AND Service Type on the record must match one of the MULTI-VALUE parameters selected by the user
--AND Order Type on the record must match one of the MULTI-VALUE parameters selected by the user
Currently, this works for the first selection I described above (to sum only those records with a service date <= warranty end date , however, I cannot get the syntax to also check the 2 other fields based on the parameters selected...
Sum(iif(Fields!FirstServiceDate.Value <= Fields!WarrantyEndDate.Value, CDbl(Fields!ExtendedCost.Value), CDbl(0)))
Attached is my layout. Eventually I would like initially display everything to the left of % remaining and allow the user to drill down to see the invoice details
warranty
I don't know what is your reason to use parameter to filter the dataset instead of filter your query directly. However this could be what you are looking for.
Try this:
=Sum(iif(
Fields!FirstServiceDate.Value <= Fields!WarrantyEndDate.Value
AND
Join(Parameters!MultiValSTParam.Value,",").Contains(Fields!ServiceType.Value)
AND
Join(Parameters!MultiValOTParam.Value,",").Contains(Fields!OrderType.Value)
,CDbl(Fields!ExtendedCost.Value)
,CDbl(0)
))
EDIT: Edition based on OP comments.
You should use the parameter to filter the query that is generating your dataset at T-SQL level.
Create #WarrantyEDParam (date type), #ServiceType and #OderType parameters, then use them in your query something similar to this.
select
me.equipment_id,
me.WarrantyEndDate,
me.WarrantyReserveAmnt,
so.invoice_id,
so.service_type,
so.order_type,
so.cost,
so.price
from
master_equipment me
left join sales_order so on me.equipment_id = so.equipment_id
where me.WarrantyEndDate <= #WarrantyEDParam
or so.equipment_id is null --This line was added
and so.service_type in (#ServiceTypeParam)
and so.order_type in (#OrderTypeParam)
Now you will get data filtered directly from the query, so to get the sum of ExtendedCost use:
=Sum(CDbl(Fields!ExtendedCost.Value))