• Hi

    Gsquared

    Your first query for SetFirst and Set last was tagging the setfirst to the record just before the setlast (stausid=2) but i was looking for it to tag for the very first record it found order by id as setfirst=1 and again setfirst =1 immediately after statusid=2

    statusid setfirst setlast

    1 1 0

    1 0 0

    1 0 0

    2 0 1

    1 1 0

    1 0 0

    2 0 1

    Righ now your query is tagging the setfirst=1 one record before it sees statusid=2, that do not represent the section, section is where it first starts and closed

    One more question on your second query, is that id same as column 'Row' from the previous #temptable , if not it do not exist in our previous #temptable to select?

    Sets1 (ID, SetID1) as

    (select id,

    Again , GSquared Tons of thanks for spending your valuable , SQL guru time for my tedious task

    Thanks

    Simon