Select
[No]=rtrim(No),
NameF=rtrim(FirstName),
NameL=rtrim(LastName),
BestLapTime,
OverallBestLapTime=(r2.bestlaptime) ,
FormattedOverallBestLapTime=(Case
When (r2.bestlaptime *0.0001)<61 Then
str( r2.bestlaptime * 0.0001,8,4)
Else
dbo.FormatLapTime(r2.bestlaptime)
END),
ResultID as ResultID
from Results R1
RIGHT JOIN
(select No,LastName,Firstname, min(r2.bestlaptime) bestlaptime
from Results r2 where Class='IndyCar' and bestlaptime >-1
GROUP BY No,LastName,Firstname ) as R2 on R2.No=r1.No and r2.LastName=r1.LastName and r2.Firstname=R1.FirstName
where lastlaptime>-2 and deleted=0 And RunID=8