I copied this code from another thread here (T-SQL: Opposite to string concatenation - how to split string into multiple records) and it works great for what I needed it to do but if asked, I couldn't explain exactly how it does what it accomplishes...can someone explain what the Recursive CTE is doing step by step please?
WITH Pieces(pn, start, stop) AS (
SELECT 1, 1, CHARINDEX(@sep, @s)
UNION ALL
SELECT pn + 1, stop + 1, CHARINDEX(@sep, @s, stop + 1)
FROM Pieces
WHERE stop > 0
)
SELECT pn,
SUBSTRING(@s, start, CASE WHEN stop > 0 THEN stop-start ELSE 512 END) AS s
FROM Pieces