﻿<?xml version='1.0' encoding='UTF-8'?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>SQLServerCentral / Article Discussions / Article Discussions by Author / Discuss content posted by hxd001_810  / Get given character's position from a string / 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>Thu, 24 May 2012 11:00:47 GMT</lastBuildDate><ttl>20</ttl><item><title>RE: Get given character's position from a string</title><link>http://www.sqlservercentral.com/Forums/Topic434636-1159-1.aspx</link><description>Function has a bug in it.  If the @AppPos is two higher than the last match, the result is incorrect.Exampleselect dbo.f_firstposition('abc,def',',',3)goResult:4 Incorrect One Solution - Break when you can't find the next occurrence :create function dbo.f_firstposition(@Str varchar(8000),@StrSep varchar(10),@AppPos int)returns intbegin 	declare @i int 	declare @ii int 	set @Str=rtrim(ltrim(@Str)) 	set @i=1 	select @ii=charindex(@StrSep,@Str) 	if @i=@AppPos 		return @ii 	else	 	while @AppPos&amp;gt;@i	 	begin			if charindex(@StrSep,right(@Str,len(@Str)-@ii))&amp;lt;&amp;gt;0 				select @ii=charindex(@StrSep,right(@Str,len(@Str)-@ii))+@ii 			else				begin	 				set @ii=0					break				end	 			set @i=@i+1 		end	 return @iiendgo</description><pubDate>Thu, 14 Feb 2008 13:33:09 GMT</pubDate><dc:creator>John Donaldson</dc:creator></item><item><title>Get given character's position from a string</title><link>http://www.sqlservercentral.com/Forums/Topic434636-1159-1.aspx</link><description>Comments posted to this topic are about the item [B]&lt;A HREF="/scripts/User+Defined+Function/61768/"&gt;Get given character's position from a string&lt;/A&gt;[/B]</description><pubDate>Wed, 19 Dec 2007 00:13:58 GMT</pubDate><dc:creator>hxd001_810-512717</dc:creator></item></channel></rss>
