A
Ann Scharpf
I have a query where I am calculating labor costs. It was working until I
tried to add a calculation to add the cost of living allowance (COLA) if the
pay period ending date is greater than the new year.
Here is the SQL for the whole query:
______
SELECT DISTINCT eBizHoursRecorded.Employee, eBizHoursRecorded.Project,
eBizHoursRecorded.Vendor, eBizHoursRecorded.PPEdate,
eBizHoursRecorded.HourType, Sum(eBizHoursRecorded.TotalHours) AS
SumOfTotalHours, Sum(eBizHoursRecorded.NightHours) AS SumOfNightHours,
GovtEmployeeGradeStep.Grade, GovtEmployeeGradeStep.Step,
HourTypeCodes.Category,
Sum(IIf([eBizHoursRecorded.HourType]="HG",[Base]*[TotalHours]*2,IIf([HourTypeCodes.OTPayRate]=True,[Overtime]*[TotalHours],IIf([eBizHoursRecorded.HourType]="SG",[Base]*[TotalHours]*1.25,IIf([Unpaid]=True,0,[Base]*[TotalHours])))))+Sum([NightHours]*0.1)+Sum([TotalHours]*[BenefitsRate]*[Base])
AS Cost,
Sum(IIf([PPEdate]<[NewYear],(IIf([eBizHoursRecorded.HourType]="HG",[Base]*[TotalHours]*2,IIf([HourTypeCodes.OTPayRate]=True,[Overtime]*[TotalHours],IIf([eBizHoursRecorded.HourType]="SG",[Base]*[TotalHours]*1.25,IIf([Unpaid]=True,0,[Base]*[TotalHours])))))+Sum([NightHours]*0.1)+Sum([TotalHours]*[BenefitsRate]*[Base]),((IIf([eBizHoursRecorded.HourType]="HG",[Base]*[TotalHours]*2,IIf([HourTypeCodes.OTPayRate]=True,[Overtime]*[TotalHours],IIf([eBizHoursRecorded.HourType]="SG",[Base]*[TotalHours]*1.25,IIf([Unpaid]=True,0,[Base]*[TotalHours])))))+Sum([NightHours]*0.1)+Sum([TotalHours]*[BenefitsRate]*[Base])*(1+[COLA]))))
AS Cost2, GovtWageBaseOvertime.Base, GovtWageBaseOvertime.Overtime
FROM GovtRatePercentages, ((eBizHoursRecorded INNER JOIN
GovtEmployeeGradeStep ON eBizHoursRecorded.Employee =
GovtEmployeeGradeStep.Employee) INNER JOIN HourTypeCodes ON
eBizHoursRecorded.HourType = HourTypeCodes.HourType) INNER JOIN
GovtWageBaseOvertime ON (GovtEmployeeGradeStep.Step =
GovtWageBaseOvertime.Step) AND (GovtEmployeeGradeStep.Grade =
GovtWageBaseOvertime.Grade)
WHERE (((eBizHoursRecorded.Employee) Like "Both*") AND
((GovtEmployeeGradeStep.EffectiveDate)=(select top 1 effectivedate from
GovtEmployeeGradeStep where effectivedate <= eBizHoursRecorded.PPEdate and
eBizHoursRecorded.Employee = GovtEmployeeGradeStep.Employee order by
effectivedate desc)) AND ((eBizHoursRecorded.HourType) Not Like 'L*'))
GROUP BY eBizHoursRecorded.Employee, eBizHoursRecorded.Project,
eBizHoursRecorded.Vendor, eBizHoursRecorded.PPEdate,
eBizHoursRecorded.HourType, GovtEmployeeGradeStep.Grade,
GovtEmployeeGradeStep.Step, HourTypeCodes.Category,
GovtWageBaseOvertime.Base, GovtWageBaseOvertime.Overtime
HAVING (((HourTypeCodes.Category)<>'Leave'));
_____
It was working fine until I added this field:
Cost2:
Sum(IIf([PPEdate]<[NewYear],(IIf([eBizHoursRecorded.HourType]="HG",[Base]*[TotalHours]*2,IIf([HourTypeCodes.OTPayRate]=True,[Overtime]*[TotalHours],IIf([eBizHoursRecorded.HourType]="SG",[Base]*[TotalHours]*1.25,IIf([Unpaid]=True,0,[Base]*[TotalHours])))))+Sum([NightHours]*0.1)+Sum([TotalHours]*[BenefitsRate]*[Base]),((IIf([eBizHoursRecorded.HourType]="HG",[Base]*[TotalHours]*2,IIf([HourTypeCodes.OTPayRate]=True,[Overtime]*[TotalHours],IIf([eBizHoursRecorded.HourType]="SG",[Base]*[TotalHours]*1.25,IIf([Unpaid]=True,0,[Base]*[TotalHours])))))+Sum([NightHours]*0.1)+Sum([TotalHours]*[BenefitsRate]*[Base])*(1+[COLA]))))
_____
I always get confused with these aggregate function problems. Can anyone
direct me about what I did wrong in that formula? Basically I tried to do
the following
If PPEDate<New Year, do all the calculations for each hour type, do all the
calculations for hour type and multiply by (1+COLA)
_____
Thanks so much for any help you can give me.
tried to add a calculation to add the cost of living allowance (COLA) if the
pay period ending date is greater than the new year.
Here is the SQL for the whole query:
______
SELECT DISTINCT eBizHoursRecorded.Employee, eBizHoursRecorded.Project,
eBizHoursRecorded.Vendor, eBizHoursRecorded.PPEdate,
eBizHoursRecorded.HourType, Sum(eBizHoursRecorded.TotalHours) AS
SumOfTotalHours, Sum(eBizHoursRecorded.NightHours) AS SumOfNightHours,
GovtEmployeeGradeStep.Grade, GovtEmployeeGradeStep.Step,
HourTypeCodes.Category,
Sum(IIf([eBizHoursRecorded.HourType]="HG",[Base]*[TotalHours]*2,IIf([HourTypeCodes.OTPayRate]=True,[Overtime]*[TotalHours],IIf([eBizHoursRecorded.HourType]="SG",[Base]*[TotalHours]*1.25,IIf([Unpaid]=True,0,[Base]*[TotalHours])))))+Sum([NightHours]*0.1)+Sum([TotalHours]*[BenefitsRate]*[Base])
AS Cost,
Sum(IIf([PPEdate]<[NewYear],(IIf([eBizHoursRecorded.HourType]="HG",[Base]*[TotalHours]*2,IIf([HourTypeCodes.OTPayRate]=True,[Overtime]*[TotalHours],IIf([eBizHoursRecorded.HourType]="SG",[Base]*[TotalHours]*1.25,IIf([Unpaid]=True,0,[Base]*[TotalHours])))))+Sum([NightHours]*0.1)+Sum([TotalHours]*[BenefitsRate]*[Base]),((IIf([eBizHoursRecorded.HourType]="HG",[Base]*[TotalHours]*2,IIf([HourTypeCodes.OTPayRate]=True,[Overtime]*[TotalHours],IIf([eBizHoursRecorded.HourType]="SG",[Base]*[TotalHours]*1.25,IIf([Unpaid]=True,0,[Base]*[TotalHours])))))+Sum([NightHours]*0.1)+Sum([TotalHours]*[BenefitsRate]*[Base])*(1+[COLA]))))
AS Cost2, GovtWageBaseOvertime.Base, GovtWageBaseOvertime.Overtime
FROM GovtRatePercentages, ((eBizHoursRecorded INNER JOIN
GovtEmployeeGradeStep ON eBizHoursRecorded.Employee =
GovtEmployeeGradeStep.Employee) INNER JOIN HourTypeCodes ON
eBizHoursRecorded.HourType = HourTypeCodes.HourType) INNER JOIN
GovtWageBaseOvertime ON (GovtEmployeeGradeStep.Step =
GovtWageBaseOvertime.Step) AND (GovtEmployeeGradeStep.Grade =
GovtWageBaseOvertime.Grade)
WHERE (((eBizHoursRecorded.Employee) Like "Both*") AND
((GovtEmployeeGradeStep.EffectiveDate)=(select top 1 effectivedate from
GovtEmployeeGradeStep where effectivedate <= eBizHoursRecorded.PPEdate and
eBizHoursRecorded.Employee = GovtEmployeeGradeStep.Employee order by
effectivedate desc)) AND ((eBizHoursRecorded.HourType) Not Like 'L*'))
GROUP BY eBizHoursRecorded.Employee, eBizHoursRecorded.Project,
eBizHoursRecorded.Vendor, eBizHoursRecorded.PPEdate,
eBizHoursRecorded.HourType, GovtEmployeeGradeStep.Grade,
GovtEmployeeGradeStep.Step, HourTypeCodes.Category,
GovtWageBaseOvertime.Base, GovtWageBaseOvertime.Overtime
HAVING (((HourTypeCodes.Category)<>'Leave'));
_____
It was working fine until I added this field:
Cost2:
Sum(IIf([PPEdate]<[NewYear],(IIf([eBizHoursRecorded.HourType]="HG",[Base]*[TotalHours]*2,IIf([HourTypeCodes.OTPayRate]=True,[Overtime]*[TotalHours],IIf([eBizHoursRecorded.HourType]="SG",[Base]*[TotalHours]*1.25,IIf([Unpaid]=True,0,[Base]*[TotalHours])))))+Sum([NightHours]*0.1)+Sum([TotalHours]*[BenefitsRate]*[Base]),((IIf([eBizHoursRecorded.HourType]="HG",[Base]*[TotalHours]*2,IIf([HourTypeCodes.OTPayRate]=True,[Overtime]*[TotalHours],IIf([eBizHoursRecorded.HourType]="SG",[Base]*[TotalHours]*1.25,IIf([Unpaid]=True,0,[Base]*[TotalHours])))))+Sum([NightHours]*0.1)+Sum([TotalHours]*[BenefitsRate]*[Base])*(1+[COLA]))))
_____
I always get confused with these aggregate function problems. Can anyone
direct me about what I did wrong in that formula? Basically I tried to do
the following
If PPEDate<New Year, do all the calculations for each hour type, do all the
calculations for hour type and multiply by (1+COLA)
_____
Thanks so much for any help you can give me.