I have searched and tried solving this puzzle, all help will be appreciated...
We use an online timesheet, each location captures their own attendance. A salary month is from the 23rd till the 22nd of the following month.
The 1st table "employee", I only need the employee's name, surname and employee number (wih over a hundred employees and employees leave and new ones appointed regularly) here is an example:
employee_id employee_surname employee_first_name
SAL010 Briel Stephanus
SAL021 Kwaza Nakedi
SAL032 Motshabi Kotsamere
SAL034 Nkonwana Sibusiso
SAL056 Van Wyk Ben
The 2nd table "empl_attendance" holds the data of employee attendance, updated on a daily basis, the empl_attendance_total is the important field, but if an employee is not at work for some reason, the field is "0", then the sql must output the description in empl_attendance_start, eg "OFF":
empl_attendance_date employee_id empl_attendance_start empl_attendance_stop empl_attendance_total location_id
2012/08/23 SAL034 06:00 18:00 11 Middelkraal
2012/08/24 SAL034 06:00 18:00 11 Middelkraal
2012/08/25 SAL034 06:00 18:00 11 Middelkraal
2012/08/26 SAL010 06:00 18:00 11 Middelkraal
2012/08/23 SAL021 18:00 06:00 11 Middelkraal
2012/08/24 SAL021 18:00 06:00 11 Middelkraal
2012/08/25 SAL021 AWOL 0 Middelkraal
2012/08/23 SAL032 OFF 0 Middelkraal
2012/08/24 SAL032 OFF 0 Middelkraal
2012/08/23 SAL056 18:00 06:00 11 Middelkraal
Here location_id is important as the location is pre-selected from the previous page. The desired iutput looks something like the following and starts with the 23rd of the month till the 22nd of the following month. The period is also selected on the previous page:
employee_id employee_surname employee_first_name 2012/08/23 2012/08/24 2012/08/25 2012/08/26
SAL010 Briel Stephanus 11 OFF 11 11
SAL021 Kwaza Nakedi 11 11 AWOL 11
SAL032 Motshabi Kotsamere OFF OFF 8 8
SAL034 Nkonwana Sibusiso 11 11 11 OFF
SAL056 Van Wyk Ben 11 AWOL 8 8
My first time with pivot tables, my dates change from month to month and the employees may change at any given time...