@ Steve Collins,
Great try/good thinking. I'm thinking, though, that just about anything you add to it is going to slow it way down... especially since, if you read the article, the original performance problem was concatenation.
I'm honestly a little bit surprised that you're justifying a sort because it has a low row count. We know how that usually works out.
The function is this article served well for a long time but it has soundly been beaten for performance after 2012 came out by Eirikur Eiriksson. His good code still avoids concatenation and his change was super simple... Basically, he replaced CHAR index with LEAD. Prior to him posting his solution, he asked me to test it for him and I tested for accurate functionality and performance... It IS ACCURATE and it IS TWICE AS FAST as the original (getting real close to CLR speeds).
With that I'll say that if you're using 2012 or above, I strongly recommend you upgrade your function to his code, with due credit, of course.
Here's the link to Eirikur's article (the code is in Part 1 of his fine article).
If you want to performance test against something, you should performance test against Eirikur's code and I should have Steve Jones update this article to point to Eirikur's.
is pronounced "ree-bar
" and is a "Modenism
" for R
First step towards the paradigm shift of writing Set Based code:
________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.
"Change is inevitable... change for the better is not".
"Dear Lord... I'm a DBA so please give me patience because, if you give me strength, I'm going to need bail money too!"
How to post code problems
How to Post Performance Problems
Create a Tally Function (fnTally)