Here is something to get you started. As I was writing it, it turned out to be more convoluted than what I thought it would be when I started writing it. So it is possible that you can write a simpler algorithm for it, so use this as something to compare to or something to get started with. You will need the DelimiterSplit8K from here: http://www.sqlservercentral.com/articles/Tally+Table/72993/