Laurie is right. Please post DDL, Sample Data and the Expected Result and we will give you a sample solution using a Recursive CTE.
Vinu Vijayan
For better and faster solutions please check..."How to post data/code on a forum to get the best help" - Jeff Moden[/url] 😉