Salient Solutions

wrasslin ones and nones for fun and profit - Sky Sanders' Blog
Get your own ranked flair here
posts - 92, comments - 102, trackbacks - 0

TSQL: another inline string split

 

I found this one somewhere on SqlTeam.com forums…

DECLARE @sep char(1), @s nvarchar(1024)

SET @sep  = ','
SET @s  = 'a,b,c';
	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 1024 END) AS s
	FROM Pieces


Technorati tags:

Print | posted on Thursday, January 28, 2010 1:19 PM |

Feedback

No comments posted yet.

Post Comment

Title  
Name  
Email
Url
Comment   
Please add 3 and 8 and type the answer here:

Powered by: