Looks like a job for a recursive query.
Make up some sample data so we can help you out. (Create table + inserts + clean up)
Or you could check out the great SQLServerCentral articles and blogs on the subject.
For better, quicker answers on T-SQL questions, read
Jeff Moden's suggestions.[/url]
"Million-to-one chances crop up nine times out of ten." ― Terry Pratchett, Mort