• Hi,

    try this one, I hope it will help:

    select
      bh.Tank_no, bh.Start_time, bh.End_time,
      ts.Output_Reading - te.Output_Reading as Trend_Tonne,
      eds.Output_Reading - ede.Output_Reading as External_Data_Tonne
    from
      Batch_History as bh
      inner join Trend as ts -- Trend start
        on (ts.Tank_no = bh.Tank_no) and (ts.Time_Stamp = bh.Start_time)
      inner join Trend as te -- Trend end
        on (te.Tank_no = bh.Tank_no) and (te.Time_Stamp = bh.End_time)
      inner join External_Data as eds -- External data start
        on (eds.Tank_no = eds.Tank_no) and (eds.Time_Stamp = bh.Start_time)
      inner join External_Data as ede -- External data end
        on (ede.Tank_no = bh.Tank_no) and (ede.Time_Stamp = bh.End_time)
    order by
      bh.Tank_no
    

    By the way, is the example incorrect ? Shouldn't the Output_Reaging value for Start_Time (12/21/2004 2:56:45 PM) be 105 instead of 107 ?

    Regards,

    Goce.