> >select a.name > ,a.phase as fromphase > ,b.phase as tophase > ,a.starttime > ,b.endtime > ,DATEDIFF( S,a.starttime,b.endtime) as elapsed > from timephases a > inner join timephases b > on a.name = b.name and a.phase<=b.phase > order by a.name,fromphase,tophase > >Very nice - I'd suggest you avoid arbitrarily assigning a, b, c. t1 and t2 would be a little more appropriate than a, b.