SELECT t1.* FROM dbo.co_Pat_HeightWeightHistory t1 INNER JOIN ( SELECT FLOOR(CAST(TransactionDT AS float)) AS dGroup, MAX(TransactionDT) AS TransactionDT FROM dbo.co_Pat_HeightWeightHistory WHERE patientID = @PatientID GROUP BY FLOOR(CAST(TransactionDT AS float)) ) t2 ON t1.TransactionDT = t2.TransactionDT WHERE patientID = @PatientID order by pathwid Desc