I was surprised to see the implementation of CTE recursion (in 2005 at least) performed similarly too inbuilt functions for small string lengths (read napkin test of up to 400) for the last example compared to
SELECT @str2 = SUBSTRING(@Str1,1,@offset-1) + @char + Substring(@Str1,@offset+1,len(@str1))
The elapsed time was comparable
The recursive reported measurable cpu time and 2 worktable scans
The inbuilt did not report anything
Forgive if I am new to this but does that mean that inbuilt functions don't add to reported CPU ?
The inbuilt in a scalar select didn't generate a query plan on execution; I guess it wasn't considered worth caching.