Table A
Calid | EffectiveFrom
---
2 | 10 Jun 2016
---
5 | 20 Nov 2016
------
7 | 05 Jan 2017
--
Calid 2 is to be followed by a person from 10 Jun onwards , from 20 Nov calid 5 is to be followed and so on....
Table B contains details of the calid (all working dates) .
Table B
CAlid | WorkingDate
2 | 1 Jan 2016
2 | 2 Jan 2016
2 | 4 Jan 2016 till 31 Dec all working dates are present
5 | 1 Jan 2016
5 | 2 Jan 2016
5 | 3 Jan 2016
5 | 5 Jan 2016 till 31 dec all working dates are present
and so on all working dates of calid 7 are present. A report is to be generated to find total working days for the person who followed calid as in Table A. Report should contain days like Calid | Date (from Table B). This is to be achieved with select statement (no procedure since it's part of view). In table A i don't have effectiveTo date column.
Details: Table B contains all the working days (read dates) of a given year. Calid is calendar id for a particular calendar. Say calid 2 means list of all the working days in Japan and Calid 5 gives the lists all the working days/dates for a year in Dubai. An employee moves across different locations from Japan to Dubai so his/her working days change accordingly. At the end of the year, it is to be calculated how many days was the employee supposed to work. Table A contains the history of the employee calendar movements during an year. An entry is added on the day on which an employee moves to another location and start following different location calendar. The EffectiveFrom tells the date from which a particular calendar is followed. This piece of logic is to be put together with another code in a view so restrictions of a view are intact.
I’ve edited the question to make it clear as commented by @philipxy .