|
|
Question : IFF Statement
|
|
I have a query that gives me the following results:
BegHours EndingHours TotalTimeRun
36.2 36.7 30 Minutes
The TotalTimeRun is a calculated field. I would like to add an IFF statement to the calculated field:
If BegHours is empty (or 00.0) then TotalTimeRun = 00.0
Here is the SQL of my query:
SELECT tGenHours.[WO#], tGenHours.MAXEQNUM, tGenHours.[Gen#], tGenHours.Month, tGenHours.BegHours, tGenHours.NoLoadHrs, tGenHours.Loadhours, ([LoadHours]-[BegHours])*60 AS ElapsedTimeInMinutes FROM tGenHours;
Thanks
Alexander
|
Answer : IFF Statement
|
|
In place of:
([LoadHours]-[BegHours])*60 AS ElapsedTimeInMinutes
Do:
IIF(ConvertNulls([BegHours],0) = 0, 0,([LoadHours]-[BegHours])*60) AS ElapsedTimeInMinutes
ConvertNulls() you may already have (it sometimes called NtoZ). If not, I've posted it below. Just put the code in a module. If this is A97 or better, You can just use Nz() (it's built in).
The statement would then be:
IIF(NZ([BegHours],0) = 0, 0,([LoadHours]-[BegHours])*60) AS ElapsedTimeInMinutes
JimD.
'---------------------------------------------------------------------------- ' FUNCTION : ConvertNulls ' ' PURPOSE : Converts the specified variant to a new value if it ' is null, otherwise it returns the variant. '---------------------------------------------------------------------------- Function ConvertNulls (v As Variant, subs As Variant) As Variant If (IsNull(v)) Then ConvertNulls = subs Else ConvertNulls = v End If End Function
|
|
|
|
|