Consider the following table schema
Employee(Id int primary key,Name varchar(255))
EquipMent(Id int primary key ,EquipmentName varchar(255))
EquipmentMapping(Id int primary key,EmployeeId varchar(255),EquipmentId int)
Consider the following data present in these tables as
Employee
(Id,Name)
(1,Jhon)
(2,Max)
EquipMent
(Id,EquipmentName)
(1,Hammer)
(2,Axe)
(3,Screw Driver)
EquipmentMapping
(Id,EmployeeId,EquipmentId)
(1,1,1)
(2,1,2)
(3,2,1)
I want to create a view which will have the following schema as
EmployeeEquipmentMappingView(Id int identity(1,1),EmployeeId int,Equipment1Id int,EquipMent2Id int)
Here the constraints are the employee cannot have more than 2 equipment mapped against him.
I want to select these two equipment mapped against him in Equipment1Id and EquipMent2Id columns.
The output will look like
Select * from EmployeeEquipmentMappingView
(Id ,EmployeeId ,Equipment1Id ,EquipMent2Id )
(1,1,1,2)
(2,2,1,NULL)