• Here is one way of doing it:

    With MyCTE as(

    select RT1.*, RT2.TimeStamp as EndTimeStamp,datediff(second,RT1.TimeStamp,RT2.TimeStamp) as DiffInSeconds

    from RunningTime RT1 LEFT JOIN RunningTime RT2 ON RT1.Id = RT2.Id - 1)

    select *,

    right ('000' + CAST (DiffInSeconds / 60 /60 as varchar(4)), 3) -- Hours part

    + ':' + right ('0' + CAST (DiffInSeconds / 60 % 60 as varchar(2)),2) --Minutes part

    + ':' + right ('0' + CAST (DiffInSeconds % 60 as varchar(2)),2) --seconds part

    from MyCTE

    Adi

    --------------------------------------------------------------
    To know how to ask questions and increase the chances of getting asnwers:
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

    For better answers on performance questions, click on the following...
    http://www.sqlservercentral.com/articles/SQLServerCentral/66909/