• In the first query, change:

    and C1.Row = C3.Row+1

    to:

    and C1.Row = C3.Row-1

    See if that gets you what you need.

    On the second query, I often call the row_number column in a CTE "Row". It's generic for me. Doesn't matter what you call it.

    - Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
    Property of The Thread

    "Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon