I'm new to SQL, so forgive me if I get it wrong.
I have one table called Employees, where I have columns for:
EmployeeID - This is Int Identity (1,1)
FirstName
LastName
I have a second table called Calendar, with calendar information populated over the next 50 years. Columns:
FullDate
Year
Month
Week
DayofWeek
DayofMonth
DayofYear
TypeofDay - (Weekday, Weekend, Bank holiday etc)
Now that I'm a little confused - it seems to me that I need a third table (Table 3), which links the two tables above, so I have a table with something like:
TableId
FullDate - linked from calendar table
EmployeeID - linked from employee table
FirstName - linked from employee table
LastName - linked from employee table
Shift1Text
Shift2Text
If my understanding is correct, I can use a command like:
select * from Table3 where FullDate = **Chosen Date / DateRange**
so I get the output line by line:
Table ID | FullDate | EmployeeID | FirstName | LastName | Shift1Text | Shift2Text
---------+------------+------------+-----------+----------+------------+------------
1 | 22/06/2015 | 1 | Joe | Blogs | SomeText | SomeText
2 | 22/06/2015 | 2 | Fred | Smith | SomeText | SomeText
3 | 22/06/2015 | 3 | Bob | Jones | SomeText | SomeText
4 | 23/06/2015 | 1 | Joe | Blogs | SomeText | SomeText
5 | 23/06/2015 | 2 | Fred | Smith | SomeText | SomeText
etc.
The problem is that I have no idea how to link tables in this way or automatically fill the rows of the third table with information about the date and employee from the first two tables.