I have a table that contains 4 columns EmployeeId, PeriodBeginDate, PeriodEndDate, HoursWorked. I can't change the structure of the table as it is from a packaged Payroll Software application. This table stores only 1 row for a Salaried Person for the entire pay period. The data looks like this:
EmployeeId, PeriodBeginDate, PeriodEndDate, HoursWorked
1121 6/27/2016 7/11/2016 80
1304 6/27/2016 7/11/2016 80
What I need to do is get a row for each day in the Pay Period Range in a sql view by employeeid. Ideally I could then calculate the average number of hours per day (excluding saturday and sundays) and then have the average per day appear on a row for that day. It would ideally look like this:
EmployeeId, PeriodDay, HoursWorked
1121 6/27/2016 8
1121 6/28/2016 8
1121 6/29/2016 8
and so on...
Any ideas on how to something like this? Thinking coalesce, pivot or something but I can't seem to figure out how to get all days from the period range in a row.