I have a query with multiple criteria, where I would like to get 2 field criteria with AND condition and the rest of other fields with OR condition, but in my situation, it is considering complete criteria as OR condition. Attached is the image for your reference (Fields highlighted in RED BOXES to be compulsory fields as they are from Combo boxes. And fields highlighted in BLACK BOXES are to be worked as OR condition separately from RED Highlighted fields)
Currently, it is showing all the records despite considering the form combo box values. I have attached the SQL code for your reference.
SELECT
Master_DataBase.Function,
Sum(IIf([Status_of_Project] = "Delayed", 1, 0)) AS Delayed,
Sum(IIf([Status_of_Project] = "Awaiting Approval", 1, 0)) AS [Awaiting Approval],
Sum(IIf([Status_of_Project] = "Testing Ongoing", 1, 0)) AS [Testing Ongoing],
Sum(IIf([Status_of_Project] = "On-Hold", 1, 0)) AS [On-Hold],
Year([Project_Start_Date]) AS Expr1
FROM
Master_DataBase
GROUP BY
Master_DataBase.Function,
Year([Project_Start_Date])
HAVING
(
(
(Master_DataBase.Function) = Nz([Forms] ! [Navigator_Form] ! [FilterbyFunction],[Master_DataBase].[Function])
)
AND (
(Year([Master_DataBase].[Project_Start_Date])) = Nz([Forms] ! [Navigator_Form] ! [FilterbyYear],Year([Master_DataBase].[Project_Start_Date]) )
)
)
OR (
((Sum(IIf([Status_of_Project] = "Delayed", 1, 0))) >= 1)
)
OR (
(
(Sum(IIf([Status_of_Project] = "Awaiting Approval", 1, 0))) >= 1
)
)
OR (
(
(Sum(IIf([Status_of_Project] = "Testing Ongoing", 1, 0))) >= 1
)
)
OR (
((Sum(IIf([Status_of_Project] = "On-Hold", 1, 0))) >= 1)
);
The desired results should be displayed only if either of the criteria (Delayed, Awaiting Approval etc.,) fields has some value. if all the fields have no value or 0 for a specific function, then that result should not be displayed. Attached for your reference (In the below image, the values highlighted in red boxes should not be displayed as those have no values or 0)
Please help!!
Table as Follows:
Function Project Name Status of the Project Year
Function 1 Project 1 Completed 2021
Function 1 Project 2 On-Going 2020
Function 2 Project 3 Awaiting Approval 2021
Function 3 Project 1 On-Hold 2020
Function 4 Project 5 - 2021
etc.,
I have a form with 2 combo boxes (Year & Function), the results should be as per them and if they are empty it should show all the records which has value with any of the status
Desired Output:
Function Completed On-Going Awaiting Approval On-Hold
Function 1 1 1 0 0
Function 2 0 0 1 0
Function 3 0 0 0 1
Note: Function 4 should not appear as it has no status