• Great article. And since you are going to clean it up for "Windows" vs "Windowing", you can clean up the following typos, too 🙂

    1. "Meaning it is the only order whose most recent date (2015-10-03) has a different code (DS) that the one before it (AG) from 2015-10-02"

    ("that" should be "than")

    2. “(note this is for SQL Server 2012+ and Azure):

    “Accesses data from a subsequent row in the same result set without the use of a self-join in SQL Server 2016. ..."

    (confusing you quote from SQL Server 2016 when saying it is ok in 2012+)

    3. "Since our rows as sorted by ORDER_DATE descending, that would be what we want." ("as" should be "are")

    4. "LEAD(H1.CODE,1) --Get the code 1 row after the current row.

    OVER (PARTITION BY ORDER_ID

    ORDER BY ORDER_DATE DESC) AS PREVIOUS_CODE"

    "LEAD(H1.CODE,1) --Get the code 1 row before the current row.

    OVER (PARTITION BY ORDER_ID

    ORDER BY ORDER_DATE DESC) AS PREVIOUS_CODE" (first comment says "after" but second occurance says "before")