Click here to Skip to main content
15,891,372 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two table as mentioned EQDUMP and HRISDetails as:-

EQDump table as:-

ECodeEname
1A
2B
3C
4D


HRISDetails Table as:-

ECodeENamemanagername
1AE
2BE
3CF
4DF
5EG
6FG


I need a query which gives me the field Empname from EqDump,Ename from EQDUmp and ManagerEmpID from HRISDetails.
The Out put should be look like this:-


ECodeEnameMCode
1A5
2B5
3C6
4D6


Please provide me the query if possible as the guys who are working on database side is on leave and i only have to write this on urgent basis:(
Posted
Comments
Om Prakash Pant 19-Jan-12 9:00am    
in HRISDetails table, do you also have managerId which is Ecode? or you need to match with the managername & ename?

 
Share this answer
 
Query should be -

SQL
SELECT eq.ECode, eq.Ename, hri.ManagerEmpID 
FROM EQDump as eq 
INNER JOIN
HRISDetails as hri
ON eq.ECode = hri.ECode


But in table you did not mentioned the column ManagerEmpID.
 
Share this answer
 
v2
Comments
Dharmenrda Kumar Singh 19-Jan-12 23:38pm    
Manager EmplyoeeID i.e MCODe is extracted from HRIS Details Table.You can find that the manager name for Emplyoee 'A" is 'E' and 'E' ECode is 5 so in the output we have to display the ECOde for Employee, Employeename and the ECODe of Manager.
SQL
select A.EmployeeName,A.Ecode,B.ECode as ManagerECode from HRISDetails as A inner join
HRISDetails as B on
A.ImmediateSupervisor=B.EmployeeName where A.Ecode in (Select SUBSTRING(ReporteeUserID,4,8) from EQDump)

<pre lang="SQL">
 
Share this answer
 
SELECT HRISDetails.Ecode, HRISDetails.Ename AS EName, EQDump.Ecode AS MCode
FROM HRISDetails INNER JOIN
EQDump ON HRISDetails.Managername = EQDump.Ename
 
Share this answer
 

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