Very nice, thanks for the article
As an old c++ guy, i learned that declarations should be
outside a controlling statement when possible
Otherwise, you are allocating and deallocating those items in every iteration
WHILE (@pos < @len)
BEGIN
DECLARE @offset INT
DECLARE @sub VARCHAR(2048)
Ordering like this, results in one single allocation
DECLARE @offset INT
DECLARE @sub VARCHAR(2048)
WHILE (@pos < @len)
BEGIN
...