This query solved my problemdeclare @Reporties table (EmployeeName varchar(50), Reporting_Manager varchar(50))insert @Reporties (EmployeeName,Reporting_Manager)( SELECT H.EmployeeName, H.ReportingManagerName FROM HR AS H UNION ALL select HR2.EmployeeName,HR3.EmployeeNamefrom HR HR1, HR HR2, HR HR3where HR1.EmployeeName= HR2.ReportingManagerName and HR1.ReportingManagerName = HR3.EmployeeName)SELECT distinct EmployeeName, Reporting_ManagerFROM @ReportiesORDER BY EmployeeName
VRN