<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://www2.sqlblog.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Splitting a string of unlimited length</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx</link><description>There are many techniques for splitting a string in T-SQL (in other words, taking a character-delimited string and producing a table of the values), the best of which are encapsulated in Erland Sommarskog's famous article . My favorite of his string splitting</description><dc:language>en</dc:language><generator>CommunityServer 2.1 SP2 (Build: 61129.1)</generator><item><title>re: Splitting a string of unlimited length</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx#991</link><pubDate>Wed, 14 Mar 2007 06:15:54 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:991</guid><dc:creator>Tiraj</dc:creator><description>&lt;p&gt;Well it says &amp;quot;Using the function is quite simple&amp;quot;&lt;/p&gt;
&lt;p&gt;But im having problems (errors) even while tring to create the function...&lt;/p&gt;
</description></item><item><title>re: Splitting a string of unlimited length</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx#1006</link><pubDate>Sun, 18 Mar 2007 16:13:32 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:1006</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;What error are you seeing? &amp;nbsp;It works fine on this end...&lt;/p&gt;
</description></item><item><title>re: Splitting a string of unlimited length</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx#1157</link><pubDate>Thu, 19 Apr 2007 06:22:56 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:1157</guid><dc:creator>Ali</dc:creator><description>&lt;p&gt;It works fine. but when I use it in a Stored Procedure it gives error:&lt;/p&gt;
&lt;p&gt;Incorrect syntax near 'SplitString'.&lt;/p&gt;
</description></item><item><title>re: Splitting a string of unlimited length</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx#3577</link><pubDate>Thu, 29 Nov 2007 04:55:20 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:3577</guid><dc:creator>Asghar</dc:creator><description>&lt;p&gt;Hi Adam this is a great function but I have got string with such as (&amp;quot;hello&amp;quot;,&amp;quot;sdfsfs&amp;quot;,....)&lt;/p&gt;
&lt;p&gt;My problem is how can I pass two parremeters such as , and &amp;quot;&amp;quot;.&lt;/p&gt;
&lt;p&gt;and how can I insert the values into a table&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;
</description></item><item><title>re: Splitting a string of unlimited length</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx#4906</link><pubDate>Tue, 05 Feb 2008 21:07:30 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4906</guid><dc:creator>David </dc:creator><description>&lt;p&gt;Had to change the last section of the code to get it to work beyond 8,000 characters. &amp;nbsp;Great approach though.&lt;/p&gt;
&lt;p&gt;_________________________________&lt;/p&gt;
&lt;p&gt;--Start next chunk&lt;/p&gt;
&lt;p&gt;SET @SplitStart = @SplitEnd + 1&lt;/p&gt;
&lt;p&gt;SET @SplitEnd = @SplitEnd + 7998&lt;/p&gt;
&lt;p&gt;IF ( @SplitEnd &amp;gt;= DATALENGTH(@List) &amp;nbsp; )&lt;/p&gt;
&lt;p&gt; &amp;nbsp; SET @SplitEnd = DATALENGTH(@List) +1&lt;/p&gt;
&lt;p&gt;ELSE&lt;/p&gt;
&lt;p&gt;BEGIN&lt;/p&gt;
&lt;p&gt; &amp;nbsp;SELECT @SplitEnd = @SplitStart + MAX(Number)&lt;/p&gt;
&lt;p&gt; &amp;nbsp;FROM dbo.Numbers&lt;/p&gt;
&lt;p&gt; &amp;nbsp;WHERE (SUBSTRING(@List, Number, 1) = @Delimiter&lt;/p&gt;
&lt;p&gt; &amp;nbsp;OR Number = DATALENGTH(@List) + 1 &lt;/p&gt;
&lt;p&gt; &amp;nbsp; )&lt;/p&gt;
&lt;p&gt; AND Number BETWEEN @SplitStart AND @SplitEnd&lt;/p&gt;
&lt;p&gt;END&lt;/p&gt;
</description></item><item><title>re: Splitting a string of unlimited length</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx#4907</link><pubDate>Tue, 05 Feb 2008 21:36:04 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:4907</guid><dc:creator>David</dc:creator><description>&lt;p&gt;Please ignore the previous post - that didn't fix it. &amp;nbsp;The issue seemed to be with parsing the last number in the last chunk. &amp;nbsp;I added &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; AND CHARINDEX(',', @LeftSplit, Number + 1) &amp;gt; 0 &lt;/p&gt;
&lt;p&gt;to the key SELECT statement.&lt;/p&gt;
</description></item><item><title>Pattern-based split string</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx#11444</link><pubDate>Sun, 25 Jan 2009 19:52:17 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:11444</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;&amp;quot;hickymanz&amp;quot; asked in the SQL Server Central forums for a method of counting unique words in a text column.&lt;/p&gt;
</description></item><item><title>Tokenize UDF</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx#11446</link><pubDate>Sun, 25 Jan 2009 19:54:25 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:11446</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Yes, another string splitting UDF from a guy who's obvioiusly become obsessed with TSQL string splitting.&lt;/p&gt;
</description></item><item><title>re: Splitting a string of unlimited length</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx#12095</link><pubDate>Mon, 23 Feb 2009 05:15:34 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:12095</guid><dc:creator>Craig Hathaway</dc:creator><description>&lt;p&gt;Hi, this function times out when the delimiter is the &amp;lt;space&amp;gt; character - for splitting sentences into words (etc). I suspect thsi has to do with trimming...&lt;/p&gt;
&lt;p&gt;E.g. 	&lt;/p&gt;
&lt;p&gt;SELECT * &lt;/p&gt;
&lt;p&gt;FROM dbo.[SplitString]( 'test one, two, three',' ')&lt;/p&gt;
</description></item><item><title>re: Splitting a string of unlimited length</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx#12110</link><pubDate>Mon, 23 Feb 2009 16:55:23 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:12110</guid><dc:creator>Adam Machanic</dc:creator><description>&lt;p&gt;Hi Craig,&lt;/p&gt;
&lt;p&gt;Busy day at the office? &amp;nbsp;Nothing better to do than rip apart my old blog posts? &amp;lt;g&amp;gt;&lt;/p&gt;
&lt;p&gt;The function has been fixed... Thanks for reporting this!&lt;/p&gt;
</description></item><item><title>re: Splitting a string of unlimited length</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx#15335</link><pubDate>Sun, 19 Jul 2009 06:04:26 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15335</guid><dc:creator>techvslife</dc:creator><description>&lt;p&gt;Thanks. &amp;nbsp;I notice Erland has a new version, &amp;amp; it will split nvarchar(max), i.e. more than 8000 chars: (long article but search for &amp;quot;Chunking Multi-Statement Function&amp;quot;)&lt;/p&gt;
&lt;p&gt;&lt;a rel="nofollow" target="_new" href="http://www.sommarskog.se/arrays-in-sql-2005.html"&gt;http://www.sommarskog.se/arrays-in-sql-2005.html&lt;/a&gt; &amp;nbsp;&lt;/p&gt;
&lt;p&gt;(&amp;amp; btw, isn't text type deprecated now.)&lt;/p&gt;
&lt;p&gt;(haven't tested both yet.)&lt;/p&gt;
</description></item><item><title>re: Splitting a string of unlimited length</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx#15341</link><pubDate>Sun, 19 Jul 2009 16:22:38 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15341</guid><dc:creator>TechVsLife</dc:creator><description>&lt;p&gt;I altered Erland's function to include wordposition and separator position (maybe in a highly inefficient way, but it seems to work correctly). &amp;nbsp;&lt;/p&gt;
&lt;p&gt;To test it on large strings, you can run something like:&lt;/p&gt;
&lt;p&gt;SELECT * FROM dbo.tfnSplitString(REPLICATE(CAST(',AB,CD,EFG,HI,MNZ,QR,UVW,YZ1' AS nvarchar(max)), 6000), DEFAULT) ORDER BY WordPos;&lt;/p&gt;
&lt;p&gt;(Note that my numbers table is called &amp;quot;Number&amp;quot; and the number column in it is &amp;quot;Num.&amp;quot;)&lt;/p&gt;
&lt;p&gt;SET ANSI_NULLS ON&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;SET QUOTED_IDENTIFIER ON&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;CREATE FUNCTION [dbo].[tfnSplitString] ( &lt;/p&gt;
&lt;p&gt;	@StringToSplit NVARCHAR(MAX),	&lt;/p&gt;
&lt;p&gt;	@Separator NCHAR(1) = N','&lt;/p&gt;
&lt;p&gt;	) &lt;/p&gt;
&lt;p&gt;RETURNS @t TABLE (Word nvarchar(4000) NOT NULL, WordPos int not null, SepPos int not null) AS&lt;/p&gt;
&lt;p&gt;BEGIN&lt;/p&gt;
&lt;p&gt; &amp;nbsp; DECLARE @slices TABLE (&lt;/p&gt;
&lt;p&gt;				slice nvarchar(4000) NOT NULL, &lt;/p&gt;
&lt;p&gt;				slicenum int NOT NULL)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; DECLARE @slice nvarchar(4000),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @textpos int = 1,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @maxlen &amp;nbsp;int = 4000-2,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @stoppos int,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @slicenum int = 0&lt;/p&gt;
&lt;p&gt; &amp;nbsp; WHILE datalength(@StringToSplit) / 2 - (@textpos - 1) &amp;gt;= @maxlen&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; BEGIN;&lt;/p&gt;
&lt;p&gt;		 &amp;nbsp;SET @slice = substring(@StringToSplit, @textpos, @maxlen);&lt;/p&gt;
&lt;p&gt;		 &amp;nbsp;SET @stoppos = @maxlen -&lt;/p&gt;
&lt;p&gt;							charindex(@Separator COLLATE Latin1_General_100_BIN2,&lt;/p&gt;
&lt;p&gt;									 reverse(@slice));&lt;/p&gt;
&lt;p&gt;		 &amp;nbsp;INSERT @slices (slice, slicenum)&lt;/p&gt;
&lt;p&gt;			 VALUES (@Separator + left(@slice, @stoppos) + @Separator, @slicenum);&lt;/p&gt;
&lt;p&gt;		 &amp;nbsp;SET @textpos = @textpos - 1 + @stoppos + 2;&lt;/p&gt;
&lt;p&gt;		 &amp;nbsp;SET @slicenum +=1;&lt;/p&gt;
&lt;p&gt;		 &amp;nbsp;-- On the other side of the comma.&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; END;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; INSERT @slices (slice, slicenum)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; VALUES (@Separator + substring(@StringToSplit, @textpos, @maxlen) + @Separator, @slicenum);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; WITH wordget (Word, SepPos) AS (&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;SELECT ltrim(rtrim(substring(s.slice, N.Num + 1,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;charindex(@Separator COLLATE Latin1_General_100_BIN2,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s.slice, N.Num + 1) -&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N.Num - 1))), &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;charindex(@Separator COLLATE Latin1_General_100_BIN2,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s.slice, N.Num + 1)+(slicenum*@maxlen)-1&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; FROM &amp;nbsp;Number N&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; JOIN &amp;nbsp;@slices s&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ON &amp;nbsp;N.Num &amp;lt;= len(s.slice) - 1&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AND &amp;nbsp;substring(s.slice, N.Num, 1) = @Separator COLLATE Latin1_General_100_BIN2&lt;/p&gt;
&lt;p&gt; &amp;nbsp; )&lt;/p&gt;
&lt;p&gt; &amp;nbsp; INSERT @t (Word, WordPos, SepPos)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;SELECT Word, ROW_NUMBER() OVER (ORDER BY SepPos) AS WordPos, SepPos FROM wordget;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; RETURN;&lt;/p&gt;
&lt;p&gt;END&lt;/p&gt;
</description></item><item><title>re: Splitting a string of unlimited length</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx#15344</link><pubDate>Sun, 19 Jul 2009 20:12:56 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15344</guid><dc:creator>TechVsLife</dc:creator><description>&lt;p&gt;I made a one-off error (--not the first time):&lt;/p&gt;
&lt;p&gt;replace &amp;quot;(slicenum*@maxlen)-1&amp;quot; &lt;/p&gt;
&lt;p&gt;with&lt;/p&gt;
&lt;p&gt;&amp;quot;(slicenum*(@maxlen-1))-1&amp;quot;&lt;/p&gt;
&lt;p&gt;(the mistake only occurs once, or only the 'zeroth' time, depending on how you count.)&lt;/p&gt;
</description></item><item><title>re: Splitting a string of unlimited length</title><link>http://www2.sqlblog.com/blogs/adam_machanic/archive/2006/07/12/splitting-a-string-of-unlimited-length.aspx#15352</link><pubDate>Sun, 19 Jul 2009 23:18:44 GMT</pubDate><guid isPermaLink="false">21093a07-8b3d-42db-8cbf-3350fcbf5496:15352</guid><dc:creator>TechVsLife</dc:creator><description>&lt;p&gt;Sorry, recorrected (one hopes for the last time)--it wasn't a one-off error, though it looked like it. &amp;nbsp;(--also, there may be a more efficient approach to adding separator position.)&lt;/p&gt;
&lt;p&gt;NOTE: assumes the existence of a numbers table called 'Number' with an integer primary key column 'Num' that has consecutive integers (requires 4,000).&lt;/p&gt;
&lt;p&gt;SET ANSI_NULLS ON&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;SET QUOTED_IDENTIFIER ON&lt;/p&gt;
&lt;p&gt;GO&lt;/p&gt;
&lt;p&gt;CREATE FUNCTION [dbo].[tfnSplitString] ( &lt;/p&gt;
&lt;p&gt;	@StringToSplit NVARCHAR(MAX),	&lt;/p&gt;
&lt;p&gt;	@Separator NCHAR(1) = N','&lt;/p&gt;
&lt;p&gt;	) &lt;/p&gt;
&lt;p&gt;RETURNS @t TABLE (Word nvarchar(4000) NOT NULL, WordPos int not null, SepPos int not null) AS&lt;/p&gt;
&lt;p&gt;BEGIN&lt;/p&gt;
&lt;p&gt;/* &lt;/p&gt;
&lt;p&gt;assumes the existence of a numbers table called 'Number' with an integer primary key column 'Num'.&lt;/p&gt;
&lt;p&gt;*/&lt;/p&gt;
&lt;p&gt; &amp;nbsp; DECLARE @slices TABLE (&lt;/p&gt;
&lt;p&gt;				slice nvarchar(4000) NOT NULL, &lt;/p&gt;
&lt;p&gt;				RunningSliceLen int NOT NULL)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; DECLARE @slice nvarchar(4000),&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @textpos int = 1,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @maxlen &amp;nbsp;int = 4000-2,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @stoppos int,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; @RunningSliceLen int = -1&lt;/p&gt;
&lt;p&gt; &amp;nbsp; WHILE datalength(@StringToSplit) / 2 - (@textpos - 1) &amp;gt;= @maxlen&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; BEGIN;&lt;/p&gt;
&lt;p&gt;		 &amp;nbsp;SET @slice = substring(@StringToSplit, @textpos, @maxlen);&lt;/p&gt;
&lt;p&gt;		 &amp;nbsp;SET @stoppos = @maxlen -&lt;/p&gt;
&lt;p&gt;							charindex(@Separator COLLATE Latin1_General_100_BIN2,&lt;/p&gt;
&lt;p&gt;									 reverse(@slice));&lt;/p&gt;
&lt;p&gt;		 &amp;nbsp;INSERT @slices (slice, RunningSliceLen)&lt;/p&gt;
&lt;p&gt;			 VALUES (@Separator + left(@slice, @stoppos) + @Separator, @RunningSliceLen);&lt;/p&gt;
&lt;p&gt;		 &amp;nbsp;SET @textpos = @textpos - 1 + @stoppos + 2;&lt;/p&gt;
&lt;p&gt;		 &amp;nbsp;SET @RunningSliceLen = @RunningSliceLen + DATALENGTH(@Separator + left(@slice, @stoppos))/2;&lt;/p&gt;
&lt;p&gt;		 &amp;nbsp;-- On the other side of the comma.&lt;/p&gt;
&lt;p&gt;	 &amp;nbsp; END;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; INSERT @slices (slice, RunningSliceLen)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; VALUES (@Separator + substring(@StringToSplit, @textpos, @maxlen) + @Separator, @RunningSliceLen);&lt;/p&gt;
&lt;p&gt; &amp;nbsp; WITH wordget (Word, SepPos) AS (&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;SELECT ltrim(rtrim(substring(s.slice, N.Num + 1,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;charindex(@Separator COLLATE Latin1_General_100_BIN2,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s.slice, N.Num + 1) -&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;N.Num - 1))), &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;charindex(@Separator COLLATE Latin1_General_100_BIN2,&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;s.slice, N.Num+1)+(s.RunningSliceLen)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; FROM &amp;nbsp;Number N&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; JOIN &amp;nbsp;@slices s&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; ON &amp;nbsp;N.Num &amp;lt;= len(s.slice) - 1&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;AND &amp;nbsp;substring(s.slice, N.Num, 1) = @Separator COLLATE Latin1_General_100_BIN2&lt;/p&gt;
&lt;p&gt; &amp;nbsp; )&lt;/p&gt;
&lt;p&gt; &amp;nbsp; INSERT @t (Word, WordPos, SepPos)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp;SELECT Word, ROW_NUMBER() OVER (ORDER BY SepPos) AS WordPos, SepPos FROM wordget;&lt;/p&gt;
&lt;p&gt; &amp;nbsp; RETURN;&lt;/p&gt;
&lt;p&gt;END&lt;/p&gt;
</description></item></channel></rss>