﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Discuss Content Posted by Leo Peysakhovich / Article Discussions / Article Discussions by Author  / Tokenizing a String Using PARSENAME / Latest Posts</title><generator>InstantForum.NET v2.9.0</generator><description>SQLServerCentral</description><link>http://www.sqlservercentral.com/Forums/</link><webMaster>notifications@sqlservercentral.com</webMaster><lastBuildDate>Sat, 25 May 2013 00:19:48 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Tokenizing a String Using PARSENAME</title><link>http://www.sqlservercentral.com/Forums/Topic148434-163-1.aspx</link><description>&lt;P&gt;I agree that the string must not contain a . sign &lt;/P&gt;&lt;P&gt;because that is not handled in the procedure &lt;/P&gt;&lt;P&gt;I should have mentioned it as limitation of the procedure &lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt;Eli&lt;/P&gt;</description><pubDate>Tue, 28 Dec 2004 13:19:00 GMT</pubDate><dc:creator>Eli Leiba</dc:creator></item><item><title>RE: Tokenizing a String Using PARSENAME</title><link>http://www.sqlservercentral.com/Forums/Topic148434-163-1.aspx</link><description>Posting an alternative as you did was a great touch!</description><pubDate>Mon, 27 Dec 2004 17:30:00 GMT</pubDate><dc:creator>Andy Warren</dc:creator></item><item><title>RE: Tokenizing a String Using PARSENAME</title><link>http://www.sqlservercentral.com/Forums/Topic148434-163-1.aspx</link><description>&lt;P&gt;I'm sorry, I didn't intend to be unkind with my remarks. I was just trying to provide an alternative that works better for me.  Most code has limitations of some kind.&lt;/P&gt;&lt;P&gt;Happy New Year!&lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Mon, 27 Dec 2004 08:49:00 GMT</pubDate><dc:creator>mkeast</dc:creator></item><item><title>RE: Tokenizing a String Using PARSENAME</title><link>http://www.sqlservercentral.com/Forums/Topic148434-163-1.aspx</link><description>&lt;P&gt;I tend to agree, but let's be a little kinder when pointing out flaws. Part of what we hope to do here is spark debate.&lt;/P&gt;&lt;P&gt;I've used Parsename before as a hack, works well enough provided you understand the rules (splits at periods, only supports the 4 part syntax of server.db.owner.object - who thought of that?!).&lt;/P&gt;&lt;P&gt; &lt;/P&gt;&lt;P&gt; &lt;/P&gt;</description><pubDate>Mon, 27 Dec 2004 07:31:00 GMT</pubDate><dc:creator>Andy Warren</dc:creator></item><item><title>RE: Tokenizing a String Using PARSENAME</title><link>http://www.sqlservercentral.com/Forums/Topic148434-163-1.aspx</link><description>&lt;P&gt;I agree with Slawomir Mucha. Also, if the occurrence number provided exceeds the number of substrings, the last substring is returned. I prefer to return an empty string in those cases. Here is a function I use, which also allows for longer delimiters:&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;CREATE FUNCTION dbo.fGetToken(  @parm varchar(8000),  @delim varchar(100),  @whichOccur smallint)RETURNS varchar(8000)ASBEGIN&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;DECLARE @occur int, @spos int, @startPos int, @maxlen intDECLARE @token varchar(8000)DECLARE @delimLen int&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;-- Len() function ignores trailing blanks, so if our delimiter is a space,-- or multiple spaces, Len() will returns zero.&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;IF Len(@delim) = 0 AND DataLength(@delim) &amp;gt; 0  SET @delimLen = DataLength(@delim)  --  DataLength(@delim) * 2 for nvarcharELSE  SET @delimLen = Len(@delim)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;SET @occur = 0SET @startPos = 1SET @spos = 1 - @delimLenSET @maxLen = Len(@parm)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;WHILE @occur &amp;lt; @whichOccur AND @parm &amp;lt;&amp;gt; '' AND @parm IS NOT NULL AND @startPos &amp;lt; @maxLenBEGIN  SET @occur = @occur + 1  SET @startPos = @spos + @delimLen&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;  SET @spos = CHARINDEX( @delim , @parm, @startPos ) &lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;  IF @spos = 0    BREAKEND&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;IF @occur &amp;lt;&amp;gt; @whichOccur  SET @token = '' -- or NULLELSE  IF @spos = 0    SET @token = Substring(@parm, @startPos, 8000)  ELSE    SET @token = SubString( @parm, @startPos, @spos - @startPos)&lt;/FONT&gt;&lt;/P&gt;&lt;P&gt;&lt;FONT face="Courier New"&gt;RETURN @tokenEND&lt;/FONT&gt;&lt;/P&gt;</description><pubDate>Mon, 27 Dec 2004 07:14:00 GMT</pubDate><dc:creator>mkeast</dc:creator></item><item><title>RE: Tokenizing a String Using PARSENAME</title><link>http://www.sqlservercentral.com/Forums/Topic148434-163-1.aspx</link><description>&lt;P&gt;How will your function work for tokenizing this string:&lt;/P&gt;&lt;P&gt;server.&lt;A href="mailto:server.dbo.tblName@www.microsoft.com@This.Is.A.Token.Containing.Periods"&gt;dbo.tblName@www.microsoft.com@This.Is.A.Token.Containing.Periods&lt;/A&gt;&lt;/P&gt;&lt;P&gt;using &lt;A href="mailto:'@'"&gt;'@'&lt;/A&gt; as the separator? Well, it fails miserably. Your 'parser' can't tell between an agreed-upon separator (@ in your example) and a period. Why not just cut the string using string functions, without resorting to (probably) version-dependent, poorly-functioning hacks?&lt;/P&gt;</description><pubDate>Mon, 27 Dec 2004 03:49:00 GMT</pubDate><dc:creator>Slawomir Mucha</dc:creator></item><item><title>Tokenizing a String Using PARSENAME</title><link>http://www.sqlservercentral.com/Forums/Topic148434-163-1.aspx</link><description>Comments posted to this topic are about the content posted at &lt;A HREF=http://www.sqlservercentral.com/columnists/lPeysakhovich/tokenizingastringusingparsename.asp&gt;http://www.sqlservercentral.com/colum</description><pubDate>Mon, 29 Nov 2004 13:06:00 GMT</pubDate><dc:creator>Leo Peysakhovich</dc:creator></item></channel></rss>