• I don't know what others call this type of problem but I call them "data smears" because it's like you smearing strips of color down from one wet paint spot to another.

    I don't believe the following will be quite as fast as a Quirky Update, but it'll blow the doors off a cursor especially in the face of the correct index. And thank you VERY much for posting such clear requirements and readily consumable data!

    UPDATE ug

    SET Pressure = ca.Pressure

    FROM dbo.UpdateGaps ug

    CROSS APPLY (SELECT TOP 1 Pressure

    FROM dbo.UpdateGaps ugca

    WHERE ugca.MachineID = ug.MachineID

    AND ugca.RecordedDate <= ug.RecordedDate

    AND ugca.Pressure > 0

    ORDER BY ugca.MachineID,ugca.RecordedDate DESC) ca

    ;

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)