[Solved] Calculated Query with IIF, AND & ELSE Conditions
So, there may already be an answer for this somewhere but I can't find it.
I know it's possible to create a calculation query that uses different calculations based upon different variables using an IIF statement. I've done it before using the following and it works fine:
I would like to know if I can integrate AND and ELSE functions into the SQL at the same time. I have two goals in this:
-Simplify the above SQL so it's along the lines of IIF([Cost_Category]="BOCES",Sum( insert calculation here), ELSE Sum( insert different calculation here) AS Total_Cost
-Create a new query that has something along the lines of IIF([Canceled]="-1" AND [Paid]="0",( set Total_Cost as "0"), ELSE Sum( insert calculation here) AS Total_Cost
Is something like this possible? Thanks!
So, there may already be an answer for this somewhere but I can't find it.
I know it's possible to create a calculation query that uses different calculations based upon different variables using an IIF statement. I've done it before using the following and it works fine:
Code:
(IIf([Cost_Category]="Full Price",Sum(nz([Program_Cost])+nz([Millage_Fee])+nz([Auditorium_Cost])+nz([Cancel_Fee])),IIf([Cost_Category]="Discount",Sum(nz([Program_Cost])+nz([Millage_Fee])+nz([Auditorium_Cost])+nz([Cancel_Fee])),IIf([Cost_Category]="Swap",Sum(nz([Program_Cost])+nz([Millage_Fee])+nz([Auditorium_Cost])+nz([Cancel_Fee])),IIf([Cost_Category]="Donation",Sum(nz([Program_Cost])+nz([Millage_Fee])+nz([Auditorium_Cost])+nz([Cancel_Fee])),IIf([Cost_Category]="BOCES",Sum(nz([Cost_Per_Person])*nz([BOCES_Number_of_Participants])))))))) AS Total_Cost
-Simplify the above SQL so it's along the lines of IIF([Cost_Category]="BOCES",Sum( insert calculation here), ELSE Sum( insert different calculation here) AS Total_Cost
-Create a new query that has something along the lines of IIF([Canceled]="-1" AND [Paid]="0",( set Total_Cost as "0"), ELSE Sum( insert calculation here) AS Total_Cost
Is something like this possible? Thanks!
Last edited: