Hello,
I have 2 tables.
Table1: Emp_Profile
Emp_Code Emp_Name Rank Salary
E1 A 1 40K
E2 B 2 30K
E3 C 3 25K
E4 D 3 25K
Table2: Emp_Promotion
Emp_Code Rank
E2 1
E3 2
I need all emp. details but condition is: If employee is promoted, then Rank will comes from Emp_Promotion table.
Output looks like:
Emp_Code Emp_Name Rank Salary
E1 A 1 40K
E2 B 1 30K
E3 C 2 25K
E4 D 3 25K
Please help.

Ankit ShuklaPosted Jun 16, 2020, 5:06 AM
Jignesh KumarPosted Jun 15, 2020, 5:13 AM
Ankit ShuklaPosted Jun 15, 2020, 3:23 AM
Select
isnull(P.DESIGNATION_CD, E.JOINING_RANK_ID) as Rank,E.Gpf_No, Ca.Cader as cader,
E.FIRST_NAME + ' ' + E.MIDDLE_NAME + ' ' + E.LAST_NAME as Name , E.REL_FIRST_NAME + ' ' + E.REL_MIDDLE_NAME + ' ' +
E.REL_LAST_NAME as Father,C.CATEGORY, d.DISTRICT as homedistrict,O.OFFICE_NAME as Posting_Place, E.DOB,E.ORDER_NO , 'ptc basic training' as TrainingType,
T.Trainning_name, 'TrainingDistrict' as TrainingDistrict ,T.Start_Trainning,T.End_Trainning,
T.Secured_mark,T.Total_Mark,T.Remark_Training
from T_HR_Employee_Profile E inner join T_HR_TRAINING_DETAIL T on E.CANDIDATE_ID = T.Candidate_id
inner join HRMS_M_CATEGORY_MAPPING C on C.CATEGORY_CD = E.CATEGORY_CD
inner join m_district d on d.DISTRICT_CD = E.PERMANENT_ADDR_DISTRCT_CD
inner join M_Cader Ca on Ca.Cader_ID = E.Cadre_CD
inner join m_office_types O on O.OFFICE_CD = E.Place_Of_Posting
left join t_employee_promotion_pis P on E.Gpf_No = P.GPF_No
Jignesh KumarPosted Jun 15, 2020, 2:31 AM