• It's not quite clear what you are after, but I'll take a stab at it. This would join the "starts" to the "ends" and allow for any "adjustments" in between. From here you can do whatever math you might desire.

    select * from

    #InvLogData TheSs

    Inner join

    #InvLogData TheEs on TheSs.Manifest_Id = TheEs.Manifest_Id and TheEs.Doc_Type = 'E'

    LEFT OUTER JOIN

    #InvLogData TheAs on TheSs.Manifest_Id = TheAs.Manifest_Id and TheAs.Doc_Type = 'A'

    where TheSs.Doc_Type = 'S'