Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is there an easier way to select the Max of two calculations 1

Status
Not open for further replies.

NeilT123

Technical User
Jan 6, 2005
302
GB
I have the following IIF statement in one of my queries. The query works and returns the expected results but I wondered if there was an easier way to return the max of two values rather than using the two IIF statements below or any suggestions on how to make this query more efficient?


Code:
TotalNAppliedByOM: Round(Sum(IIf([UseInRegCalculations]=Yes,([OMApplicationRate]*[NValueFarmersOwn]),
(IIf([tblCropping].[CroppingYear]<2011,
IIf([NValueFarmersOwn]>[NValue7thRB209],([OMApplicationRate]*[NValueFarmersOwn]),([OMApplicationRate]*[NValue7thRB209])),
IIf([NValueFarmersOwn]>[NValue8thRB209],([OMApplicationRate]*[NValueFarmersOwn]),([OMApplicationRate]*[NValue8thRB209])))))))

Thank you for any suggestions
 
A little simpler:
Code:
TotalNAppliedByOM: Round(Sum(OMApplicationRate*IIf(UseInRegCalculations=Yes,NValueFarmersOwn,
IIf(tblCropping.CroppingYear<2011,
IIf(NValueFarmersOwn>NValue7thRB209,NValueFarmersOwn,NValue7thRB209),
IIf(NValueFarmersOwn>NValue8thRB209,NValueFarmersOwn,NValue8thRB209)))))

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Thanks PHV, I know that the change that you suggest is only on one small query but it is having the different view that I appreciate. I would never have thought about simplifying things by moving the common factor of "OMApplicationRate*" to the "outside" of the statement. It will be something I will consider with other statements. Thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top