You can use recursive CTE for this.. Please have a look at this and let us know if u face any problems.
http://msdn.microsoft.com/en-us/library/ms186243.aspx
http://blog.sqlauthority.com/2008/07/28/sql-server-simple-example-of-recursive-cte/
You can use recursive CTE for this.. Please have a look at this and let us know if u face any problems.
http://msdn.microsoft.com/en-us/library/ms186243.aspx
http://blog.sqlauthority.com/2008/07/28/sql-server-simple-example-of-recursive-cte/