Thank you, this worked great with very minor tweaks! I'm gonna give the 7 day overtime rule a few tries and well I stuck on this one. I posted the whole SP for more clarity of the desired results. The section labeled -- Join the WorkedHours table to sum the worked hours for the 7th day -- is what I added to tally the seventh day. The reason I am doing a sum for one day is that an employee can work twice in a day. Prior to adding this the procedure worked fine. Now it is repeating multiple entries per day. I also posted this to make sure that I am designing this properly as I am not a SQL Guru, yet. LOL.
DECLARE @WorkDate datetime ='4/6/2009' set datefirst 7 DECLARE @WorkWeek int = DATEPART(WW,@WorkDate) DECLARE @WeekStarts datetime = DATEADD(WW,DATEDIFF(WW,0,@WorkDate),-1) DECLARE @WeekEnds datetime = DATEADD(WW,DATEDIFF(WW,0,@WorkDate),5) SELECT DISTINCT (SELECT ADPCode FROM Company WHERE (Company.CompanyID = E.CompanyID)) AS [CO CODE], @WorkWeek AS [BATCH ID], AR.ADP AS [FILE #], 'WorkWeek ' + CAST(@WorkWeek AS NVARCHAR)+ ' - ' + CAST(WorkDate AS NVARCHAR) AS [BATCH DESCRIPTION], E.FirstName + ' ' + E.LAStName AS [Employee Name], '1' AS [Pay #], '' AS [Tax Frequency], W.RegularTime AS [Reg Hours], W.OverTime + W7.RegularTime7 AS [O/T Hours], W.DoubleTime + W7.OverTime7 + W7.DoubleTime7 AS [Double Time], '' AS [Piece Work], 'N' AS [Cancel Pay], '' AS [Adjust Ded Code] FROM Employee E -- Join the WorkedHours table to sum the worked hours for the first 6 days INNER JOIN (SELECT PunchID, CASE WHEN SUM(RegularTime) > 40 THEN 40 ELSE SUM(RegularTime) END AS RegularTime, CASE WHEN SUM(RegularTime) > 40 THEN ((SUM(RegularTime) - 40) + SUM(OverTime)) ELSE SUM(OverTime) END AS OverTime, SUM(DoubleTime) AS DoubleTime FROM WorkedHours WHERE (WorkDate BETWEEN @WeekStarts AND DATEADD(day, -1, @WeekEnds)) GROUP BY PunchID ) W ON E.PunchID = W.PunchID -- Join the WorkedHours table to sum the worked hours for the 7th day INNER JOIN (SELECT PunchID, SUM(RegularTime) AS RegularTime7, SUM(OverTime) AS OverTime7, SUM(DoubleTime) AS DoubleTime7 FROM WorkedHours WHERE (WorkDate = CAST(@WeekEnds AS DATE)) GROUP BY PunchID ) W7 ON E.PunchID = W.PunchID -- Join the ADP_OS3_EmployeesRoster table to add the ADP Employee [File #] INNER JOIN ADP_OS3_EmployeesRoster AR ON AR.SSN = E.SSN -- Rejoin the WorkedHours table to add the WorkDate INNER JOIN (SELECT PunchID, WorkDate FROM WorkedHours WHERE (WorkDate BETWEEN @WeekStarts AND @WeekEnds) ) WD ON E.PunchID = WD.PunchID WHERE (WorkDate BETWEEN @WeekStarts AND @WeekEnds) Order by [FILE #] SELECT @WorkWeek AS WorkWeek, @WeekStarts AS WeekStarts, @WeekEnds AS WeekEnds