I have 2 tables, one stored clocking in times and the other stores breaks taken between the ClockInLogs.TimeIn and TimeOut. There is always going to be more than 1 break for each clockintime.
ClockInLogs -
ID - int
TimeIn - DateTime
TimeOut - DateTime
Breaks -
CID - Int (joined to ClockInLogs.ID)
TimeIn - DateTime
TimeOut - DateTime
In my SQL query, I need to retrieve the total number of hours in the breaks column for each Clock In. So far I have -
SELECT
C.ID,
C.ClockDateTimeIn as 'Date',
DATENAME(dw, C.ClockDateTimeIn) as 'DayOfWeek',
C.UserID,
C.ClockDateTimeIn as 'ClockInTime',
C.ClockDateTimeOut as 'ClockOutTime',
DATEDIFF(minute, ClockDateTimeIn, ClockDateTimeOut) as 'Att'
FROM clockinlogs C
INNER JOIN breaks b on C.ID = b.CID
INNER JOIN Users u on C.UserID = u.ID
The next column needed is a total number of hours within the breaks. Basically, for each Break.TimeIn and Break.TimeOut, work out the difference in hours, then add each break up.
I hope this makes sense!