b ghanekar (3/6/2013)
I think the window functions should be of help here.Please repost the data I am not able to get the data you have posted.
The fourth post on this thread has a .txt attachment which contains the ddl and dml and it works just fine. I'd be very interested to see how window functions might be used in a solution.
For fast, accurate and documented assistance in answering your questions, please read this article.
Understanding and using APPLY, (I) and (II) Paul White
Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden