• Why do you need this to be in a CLR function?

    There is a very good T-SQL function which you can find in my signature post by Jeff, but for ease of use here is the link http://www.sqlservercentral.com/articles/Tally+Table/72993/