SELECT newid() as ID, D.anNO,  case when D.anNo = 1 then T.acCityStart else S.acCity end as acCitySource, D.acCity acCityDestination, 1 as anType,
D.acCarRegNo, D.acViacle, V.anMileage anValue                        
FROM vHR_TrvlReportPoz D
join vHR_TrvlReport T on T.acKey = D.acKey
join vHR_TrvlValueItemPrimCurrency V on V.acKey = D.acKey and V.anNO = D.anNO                                                                            
left join vHR_TrvlReportPoz S on S.acKey = D.acKey and S.anNO = D.anNo-1
Where D.acKey=@acKey
UNION ALL                     
Select ID, anNO, acCitySource, acCityDestination, anType,acCarRegNo, acViacle, 0.0 anValue from (                              
SELECT TOP 1 newid() as ID, D.anNO, D.acCity as acCitySource, T.acCityFinish acCityDestination, 2 as anType,
D.acCarRegNo, D.acViacle    
FROM vHR_TrvlReportPoz D
join vHR_TrvlReport T on T.acKey = D.acKey
Where D.acKey=@acKey
Order by D.anNO desc) KONC                                                               
ORDER BY anType, anNo