select distinct P.acKey, P.acKeyView, P.adDate, P.adDateDue, P.adDateOfAppr, P.acPayPurpose2, P.anAmount,
case when Coalesce(Z.acStatus, ' ') <> ' ' THEN Z.acStatus else P.acStatus end as acStatus, P.acCurrency,
V.acKey as acKeyTrvl, P.acDocType
from vHE_PayOrder P 
join tHR_LinkTrvlPayOrder V on P.acKey = V.acLnkKey 
left join tHE_LinkPayOrderPayOrder L 
join tHE_PayOrder Z on L.acKey = Z.acKey on L.Aclnkkey = P.acKey and L.acType = 'VV' 
where V.acKey = @acKey and V.acType = N'VI' 
ORDER BY P.acKey

