Click here to Skip to main content
15,906,329 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a table called Employee with sample Data as follow:


EmpIDEmpNameReporteeToEmpIDEmpCode
1Ram3ABC111
2Shyam3ABC112
3karan4ABC113

4Alex4ABC114


Here the Column "ReporteeToEmpID" is referring the "EmpID" to whom the Emp is Reporting to.For example Ram's "ReporteeToEmpId" is 3 i.e. Karan EmpID so Ram is Reporting to Karan.

I need the Result as :

EmpCodeEmpNameReportingToEmployeeName
ABC111RamKaran
ABC112Shyamkaran
ABC113KaranAlex
ABC114AlexAlex
Posted
Updated 28-Dec-11 21:40pm
v3
Comments
Rajesh Anuhya 29-Dec-11 3:30am    
Sounds like Home work..

1 solution

try this query..

SQL
select A.EmpCode, A.EmpName, B.EmpName as 'Reporting To Employee' from EmpTable as A inner join EmpTable as B on A.ReporteeToEmpID=B.EmpID


hope it works..
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900