i HAVE Four table in sql database,
PointCategory Table
id pointname point_Category
1 xxx A
2 XCV B
Second Table
EmployeeCategory Table
id Employee_Id Emp_Category
1 mmm A
2 DDD B
3 XXX A
Third Table
EmployeeStatus
id Employee_Id EmpStatus_Id EndDATE
1 mmm 1 2015-2-13
2 mmm 2 2015-2-14
3 mmm 3 2015-2-15
4 XXX 1 2015-2-13
5 XXX 3 2015-2-12
and Last one Allocation tABLE
Id pointCategory_Id Employee_Id DATE
1 A mmm 2015-2-13
2 B XXX 2015-2-13
I WANT a Query or series of Queries that fullfill the following step.
1.First Check Employee Category FROM employeeCategory table.Get A list of employee with same category.
2.then from EmpStatus table where multiple records against same employee are present
,get last record of all employee which have same category AND same EmployeeStatusType_Id as WE get in above point.
3.then check against each employee THAT we get from EmployeeStatus Table that
if that Employee is allocated at point which has category "A" previously ,
THEN allocate that Employee at a point WHICH HAS category "B".