Thursday, February 27, 2014

Need a PIVOT-like solution

;with cte as (select PatientID, LabDate, ROW_NUMBER() over (partition by PatientID ORDER BY LabDate) as Rn FROM dbo.LabsPerPatient)


SELECT * from cte PIVOT (max(LabDate) FOR Rn IN ([1],[2],[3],[4])) pvt


-------------------


The above will display 4 first dates per patient.




For every expert, there is an equal and opposite expert. - Becker's Law





My blog




My TechNet articles



No comments:

Post a Comment