I think this is the wrong appraoch. SQL is a data language. There ought to be a CHECK() in the DDL to protect data integrity. The non-relational UDF code cannot be optimized. The mindset here is so linked into procedural coding and not sets, that he starts the sring with a zero position, just like an array. He also writes with local varibles and loops!

Books in Celko Series for Morgan-Kaufmann PublishingAnalytics and OLAP in SQL Data and Databases: Concepts in Practice Data, Measurements and Standards in SQLSQL for SmartiesSQL Programming Style SQL Puzzles and Answers Thinking in SetsTrees and Hierarchies in SQL