• I made an assumption that you make two readings and two readings only on each machine. That assumption let's me join the table on itself and put the two readings on one line. [EDIT: Sean posted his response while I was working on mine. We had the same idea. The only difference is that I added more data such as the reading number and the actual time differences. But essentially the same query.]

    SELECT

    tt1.ID

    ,tt1.Mach_Name AS [MachineName]

    ,tt1.Div_Time AS [1stDivTime]

    ,tt1.Filled_Time AS [1stFilledTime]

    ,tt1.Diff1 AS [1stDuration]

    ,tt2.Div_Time AS [2ndDivTime]

    ,tt2.Filled_Time AS [2ndFilledTime]

    ,DATEDIFF(MINUTE,tt2.Div_Time,tt2.Filled_Time) AS [2ndDuration]

    ,DATEDIFF(MINUTE,tt2.Div_Time,tt2.Filled_Time)-tt1.Diff1 AS [Diff]

    FROM

    (

    SELECT

    *

    ,DATEDIFF(MINUTE,Div_Time,Filled_Time) AS [Diff1]

    FROM

    #TempTable

    ) AS tt1

    INNER JOIN

    #TempTable AS tt2

    ON tt1.ID = tt2.ID-1

    AND tt1.Reading = 1

    AND DATEDIFF(MINUTE,tt2.Div_Time,tt2.Filled_Time)-tt1.Diff1 <> 0

    Output:

    ID MachineName 1stDivTime 1stFilledTime 1stDuration 2ndDivTime 2ndFilledTime 2ndDuration Diff

    1 Machine5 2013-01-01 01:00:00.000 2013-01-01 12:10:00.000 670 2013-01-01 01:00:00.000 2013-01-01 12:15:00.000 675 5

    7 Machine11 2013-01-01 01:45:00.000 2013-01-01 12:40:00.000 655 2013-01-01 01:45:00.000 2013-01-01 12:28:00.000 643 -12