I wouldn't use that function. The loops will make it very slow.
Try this one: http://www.sqlservercentral.com/articles/Tally+Table/72993/
Gail Shaw
Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability