SELECT MgrEmp.UserName AS MgrName
,MgrEmp.Email AS MgrEmail
,EngEmp.UserName AS EngName
,EngEmp.Email AS EngEmail
,vsm.PguName
,vsm.SkillName
,uccps.Rating
,a.CompletedDate AS AssessmentCompletedDate
,EngEmp.PrimaryRole
,EngEmp.SecondaryRole
,EngEmp.Country
,EngEmp.ServiceTower
,EngEmp.D_O_J
,Cast(datediff(day, EngEmp.D_O_J, GETDATE()) / 365.2425 AS DECIMAL(6, 1)) TenureInYears
,EngEmp.ManagerName2
,EngEmp.ManagerName3
FROM dbo.[User] EngEmp
INNER JOIN dbo.[User] MgrEmp ON EngEmp.InternalManagerId = MgrEmp.UserId
AND MgrEmp.IsActive = 1
LEFT JOIN dbo.UserXCenter uc ON EngEmp.UserId = uc.UserId
AND uc.IsActive = 1
AND uc.CenterId = 1
LEFT JOIN dbo.UserCenterXCenterPguSkill uccps ON uc.UserXCenterId = uccps.UserXCenterId
AND uccps.IsActive = 1
LEFT JOIN dbo.vw_SkillMaster vsm ON uccps.CenterXPGUXSkillId = vsm.CenterPguSkillId
LEFT JOIN dbo.Assessment a ON uccps.LatestAssessmentId = a.AssessmentId
WHERE EngEmp.IsActive = 1
AND (
MgrEmp.Email = ''
OR EngEmp.ManagerName2 LIKE '%%'
)
ORDER BY MgrEmp.UserName
,EngEmp.UserName