Monday, June 27, 2011

Parse string characters and separate them

DECLARE @String NVARCHAR(99) = N'abcdefghijk' ;

;WITH Numbers
AS ( SELECT 1 AS Number
UNION ALL
SELECT Number + 1
FROM Numbers
WHERE Number < 99
)
SELECT SUBSTRING(@String, Number, 1) AS SingleChar
FROM Numbers
WHERE Number <= LEN(@String) ;

No comments: