AdventureWorks

Basic Index   Expanded Index

View Name:HumanResources.vEmployeeDepartmentHistory
Description:Returns employee name and current and previous departments.

FieldTypeNulls?
EmployeeIDintNo
Titlenvarchar (8)Yes
FirstNamenvarchar (50)No
MiddleNamenvarchar (50)Yes
LastNamenvarchar (50)No
Suffixnvarchar (10)Yes
Shiftnvarchar (50)No
Departmentnvarchar (50)No
GroupNamenvarchar (50)No
StartDatedatetimeNo
EndDatedatetimeYes

CREATE VIEW [HumanResources].[vEmployeeDepartmentHistory]
AS
SELECT
e.[EmployeeID]
,c.[Title]
,c.[FirstName]
,c.[MiddleName]
,c.[LastName]
,c.[Suffix]
,s.[Name] AS [Shift]
,d.[Name] AS [Department]
,d.[GroupName]
,edh.[StartDate]
,edh.[EndDate]
FROM [HumanResources].[Employee] e
INNER JOIN [Person].[Contact] c
ON c.[ContactID] = e.[ContactID]
INNER JOIN [HumanResources].[EmployeeDepartmentHistory] edh
ON e.[EmployeeID] = edh.[EmployeeID]
INNER JOIN [HumanResources].[Department] d
ON edh.[DepartmentID] = d.[DepartmentID]
INNER JOIN [HumanResources].[Shift] s
ON s.[ShiftID] = edh.[ShiftID];