Considering the filter:
- Start: 14/09/2015 (Monday)
- End: 20/09/2015 (Sunday)
I have this result from a query from 14/09 until 20/09:
╔════════════╦══════════╦══════════════╦═══════════╗
║ Date ║ Employee ║ EmployeeType ║ Type ║
╠════════════╬══════════╬══════════════╬═══════════╣
║ 14/09/2015 ║ John ║ Permanent ║ Timesheet ║
║ 14/09/2015 ║ Silva ║ Permanent ║ Timesheet ║
║ 16/09/2015 ║ John ║ Permanent ║ Timesheet ║
║ 17/09/2015 ║ Airn ║ Casual ║ Timesheet ║
╚════════════╩══════════╩══════════════╩═══════════╝
I need to return all the missing dates if the employee is 'Permanent' and if the day missing is from 'Monday to Friday', as follows:
╔════════════╦══════════╦══════════════╦═══════════╗
║ Date ║ Employee ║ EmployeeType ║ Type ║
╠════════════╬══════════╬══════════════╬═══════════╣
║ 14/09/2015 ║ John ║ Permanent ║ Timesheet ║
║ 14/09/2015 ║ Silva ║ Permanent ║ Timesheet ║
║ 15/09/2015 ║ John ║ Permanent ║ Missing ║
║ 15/09/2015 ║ Silva ║ Permanent ║ Missing ║
║ 16/09/2015 ║ John ║ Permanent ║ Timesheet ║
║ 16/09/2015 ║ Silva ║ Permanent ║ Missing ║
║ 17/09/2015 ║ John ║ Permanent ║ Missing ║
║ 17/09/2015 ║ Airn ║ Casual ║ Timesheet ║
║ 17/09/2015 ║ Silva ║ Permanent ║ Missing ║
║ 18/09/2015 ║ John ║ Permanent ║ Missing ║
║ 18/09/2015 ║ Silva ║ Permanent ║ Missing ║
╚════════════╩══════════╩══════════════╩═══════════╝
I don't understand very well the LEAD
command in SQL Server 2012.