SELECT TOP 1 rip_rl_id,
rl_name,
rip_personnel_no,
Replace(CONVERT(CHAR(11), rip_avail_from_dt, 106), ' ', '-')
RIP_AVAIL_FROM_DT,
Replace(CONVERT(CHAR(11), rip_avail_to_dt, 106), ' ', '-')
RIP_AVAIL_TO_DT
--,RIP_AVAIL_FROM_DT,RIP_AVAIL_TO_DT
,
rip_enterprise_id,
rip_interviewer_name,
rs_status,
rip_rs_id,
rip_au_id,
au_activeyn
FROM rec_interview_schedule
LEFT OUTER JOIN rec_interviewer_pool
ON riv_rip_id = rec_interviewer_pool.rip_id
LEFT OUTER JOIN appuser
ON au_id = rec_interviewer_pool.rip_au_id
AND ris_ritm_id = @P_TYPE
AND ris_rism_id <> 9
LEFT OUTER JOIN reslevelmaster
ON reslevelmaster.rl_id = rec_interviewer_pool.rip_rl_id
LEFT OUTER JOIN resource
ON resource.rs_id = rec_interviewer_pool.rip_rs_id
WHERE riv_rcn_id = @P_CANDIDATE_ID
AND riv_ritm_id = @P_TYPE
AND riv_rism_id <> 9
AND rip_avail_to_dt IS NOT NULL
ORDER BY riv_created_on DESC