Solved
List of all employees where I'm the manager of their department or some department above
Posted on 2012-04-03
Problem:
I want a list of all employees where I'm the manager of their department or some department above (in MS SQL)
I can be a manager of one of more departments
Table 1: EMPLOYEES: columns employeecode, name, departmentcode
Table 2: MANAGERS: columns employeecode, departmentcode (employeecode is manager of departmentcode)
Table 3: DEPARTMENTS: columns departmentcode, treecode
treecode is a parent-child structure for each department, like
*TOP*parent*parent*parent*thisDepartment
example: department 0310 has treecode *TOP*B05*B0003*0310*
(0310's parent is B0003, B0003's parent is B05 and so on)
Example: if I am the manager of departments B05 and C01, I want all employees in any department having treecode LIKE '%*B05*%' or '%*C01*%' (MS SQL)