Like this?IF OBJECT_ID('tempdb..#Jobs') IS NOT NULL DROP TABLE #JobsCREATE TABLE #Jobs( ClientProvisionFK INT ,ActionPlanFK INT ,ClaimFK INT ,JobStart DATETIME ,JobALD DATETIME)INSERT INTO #Jobs (ClientProvisionFK,ActionPlanFK,ClaimFK,JobStart,JobALD)VALUES(1,9,1,'03-Oct-2011','06-oct-2011'),(1,9,2,'07-oct-2011','26-oct-2011'),(1,9,3,'09-oct-2011','27-oct-2011'),(1,9,4,'31-oct-2011',NULL)SELECT DENSE_RANK() OVER (PARTITION BY ClientProvisionFK ORDER BY JobStart ASC, CASE WHEN JobALD IS NULL THEN 1 ELSE 0 END ASC, JobALD ASC,ClaimFK ASC)AS [Ordering] ,J.ClientProvisionFK ,J.JobStart ,J.JobALDFROM #Jobs JORDER BY 1In the above example I would want the records ordered 1,2 & 3 to be merged and the output would be return Start Date 03/10/2011 and ALD 27/10/2011, plus a count of the number of records merged and the days in a job.