• sgmunson (12/2/2016)


    Glad I could help. Be sure to look up how LEAD and LAG work. They both allow for an optional "default" value, which is chosen whenever the record that LEAD or LAG is trying to reference has a NULL value, which is going to be the case whenever there is no such record, such as when you want LEAD(field, 1) when the record you are on is the last one, so there is no next record, or for LAG(field, 1) when the record you are on is the first one, so there is no previous record.

    Yes Sir I will do that..

    Your solution is very elegant indeed..Hats of to you..