<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
		>
<channel>
	<title>Comments on: SQL SERVER &#8211; UDF &#8211; Function to Convert Text String to Title Case &#8211; Proper Case</title>
	<atom:link href="http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/</link>
	<description>Notes of a SQL Server MVP and Database Administrator</description>
	<lastBuildDate>Sat, 21 Nov 2009 05:54:09 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
		<item>
		<title>By: pinaldave</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-57505</link>
		<dc:creator>pinaldave</dc:creator>
		<pubDate>Tue, 10 Nov 2009 19:38:16 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-57505</guid>
		<description>Joe Celko Sir,

That is excellent comment. I encourage every one to read this comment. http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-57503

Regards,
Pinal</description>
		<content:encoded><![CDATA[<p>Joe Celko Sir,</p>
<p>That is excellent comment. I encourage every one to read this comment. <a href="http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-57503" rel="nofollow">http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-57503</a></p>
<p>Regards,<br />
Pinal</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Joe Celko</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-57503</link>
		<dc:creator>Joe Celko</dc:creator>
		<pubDate>Tue, 10 Nov 2009 18:59:38 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-57503</guid>
		<description>A quick way is nest a bunch of function calls to built-in string functions  

1) The obvious quickie first step is to lowercase the whole string: 

UPDATE Foobar
  SET col_b = LOWER (col_b);


2)The first letter needs to be uppercase, so write that step:

UPDATE Foobar
  SET col_b = UPPER (LEFT(col_b, 1) + RIGHT (col_b, 2);

But why not put them in one update statement? 

UPDATE Foobar
  SET col_b = UPPER (LEFT(LOWER (col_b), 1) + RIGHT (LOWER (col_b), 2);


3) You can then use the REPLACE() function to uppercase letters with a blank to their left by nesting calls inside each other.  LISP programmers love this style of programming :)


UPDATE Foobar
  SET col_b = REPLACE .. 
               (REPLACE 
                  (REPLACE (REPLACE (col_b, &#039; a&#039;, &#039;A&#039;),
                     &#039; b&#039;, &#039; B&#039;),
                 ..);

Now nest the updates again  

UPDATE Foobar
  SET col_b = REPLACE .. 
              (REPLACE 
               (REPLACE (UPPER (LEFT(LOWER (col_b), 1) + RIGHT (LOWER (col_b), 2), &#039; a&#039;, &#039;A&#039;),
             &#039; b&#039;, &#039; B&#039;),
                ... ); 


This does the job in one pass thru the table and the code is portable.</description>
		<content:encoded><![CDATA[<p>A quick way is nest a bunch of function calls to built-in string functions  </p>
<p>1) The obvious quickie first step is to lowercase the whole string: </p>
<p>UPDATE Foobar<br />
  SET col_b = LOWER (col_b);</p>
<p>2)The first letter needs to be uppercase, so write that step:</p>
<p>UPDATE Foobar<br />
  SET col_b = UPPER (LEFT(col_b, 1) + RIGHT (col_b, 2);</p>
<p>But why not put them in one update statement? </p>
<p>UPDATE Foobar<br />
  SET col_b = UPPER (LEFT(LOWER (col_b), 1) + RIGHT (LOWER (col_b), 2);</p>
<p>3) You can then use the REPLACE() function to uppercase letters with a blank to their left by nesting calls inside each other.  LISP programmers love this style of programming :)</p>
<p>UPDATE Foobar<br />
  SET col_b = REPLACE ..<br />
               (REPLACE<br />
                  (REPLACE (REPLACE (col_b, &#8216; a&#8217;, &#8216;A&#8217;),<br />
                     &#8216; b&#8217;, &#8216; B&#8217;),<br />
                 ..);</p>
<p>Now nest the updates again  </p>
<p>UPDATE Foobar<br />
  SET col_b = REPLACE ..<br />
              (REPLACE<br />
               (REPLACE (UPPER (LEFT(LOWER (col_b), 1) + RIGHT (LOWER (col_b), 2), &#8216; a&#8217;, &#8216;A&#8217;),<br />
             &#8216; b&#8217;, &#8216; B&#8217;),<br />
                &#8230; ); </p>
<p>This does the job in one pass thru the table and the code is portable.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Scott</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-57421</link>
		<dc:creator>Scott</dc:creator>
		<pubDate>Sun, 08 Nov 2009 01:57:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-57421</guid>
		<description>Thanks, useful code.</description>
		<content:encoded><![CDATA[<p>Thanks, useful code.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rupesh Joshi</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-55255</link>
		<dc:creator>Rupesh Joshi</dc:creator>
		<pubDate>Wed, 26 Aug 2009 13:52:21 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-55255</guid>
		<description>Thanks a Lot!!!! But it will not work for the Aphostrophe Sign</description>
		<content:encoded><![CDATA[<p>Thanks a Lot!!!! But it will not work for the Aphostrophe Sign</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Musawar Mustafa</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-53032</link>
		<dc:creator>Musawar Mustafa</dc:creator>
		<pubDate>Tue, 16 Jun 2009 05:37:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-53032</guid>
		<description>thnx dear, to save my time  :)</description>
		<content:encoded><![CDATA[<p>thnx dear, to save my time  :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mohammed</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-52568</link>
		<dc:creator>Mohammed</dc:creator>
		<pubDate>Sat, 30 May 2009 17:48:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-52568</guid>
		<description>Thanks and keep good work.</description>
		<content:encoded><![CDATA[<p>Thanks and keep good work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan B</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-52272</link>
		<dc:creator>Jonathan B</dc:creator>
		<pubDate>Sat, 23 May 2009 17:29:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-52272</guid>
		<description>BTW, one great use of this function is another function - Get_Person_FullName, which automatically formats a Full Name from its parts.

CREATE FUNCTION [dbo].[Get_Person_FullName]
(
	@PersonID AS INT
)
RETURNS VARCHAR(255)
AS
BEGIN

DECLARE @FullName AS VARCHAR(255)
DECLARE @LastName AS VARCHAR(100)
DECLARE @FirstName AS VARCHAR(100)
DECLARE @MiddleName AS VARCHAR(100)
DECLARE @SuffixName AS VARCHAR(100)

SELECT	@LastName = LastName, @FirstName = FirstName, @MiddleName = MiddleName, @SuffixName = S.SuffixName
FROM	dbo.Persons P LEFT OUTER JOIN 
			dbo.Persons_Suffixes S ON P.SuffixID = S.SuffixID
WHERE	PersonID = @PersonID

SET @FullName = dbo.Format_TitleCase(@LastName)

IF (isnull(@FirstName,&#039;&#039;)  &#039;&#039;) AND @FirstName  &#039;The&#039;
	SET @FullName = @FullName + &#039;, &#039; + dbo.Format_TitleCase(@FirstName)

IF (isnull(@MiddleName,&#039;&#039;)  &#039;&#039;) 
	SET @FullName = @FullName + &#039; &#039; + dbo.Format_TitleCase(@MiddleName)

IF (isnull(@SuffixName,&#039;&#039;)  &#039;&#039;) 
	SET @FullName = @FullName + &#039; &#039; + @SuffixName

RETURN @FullName

END</description>
		<content:encoded><![CDATA[<p>BTW, one great use of this function is another function &#8211; Get_Person_FullName, which automatically formats a Full Name from its parts.</p>
<p>CREATE FUNCTION [dbo].[Get_Person_FullName]<br />
(<br />
	@PersonID AS INT<br />
)<br />
RETURNS VARCHAR(255)<br />
AS<br />
BEGIN</p>
<p>DECLARE @FullName AS VARCHAR(255)<br />
DECLARE @LastName AS VARCHAR(100)<br />
DECLARE @FirstName AS VARCHAR(100)<br />
DECLARE @MiddleName AS VARCHAR(100)<br />
DECLARE @SuffixName AS VARCHAR(100)</p>
<p>SELECT	@LastName = LastName, @FirstName = FirstName, @MiddleName = MiddleName, @SuffixName = S.SuffixName<br />
FROM	dbo.Persons P LEFT OUTER JOIN<br />
			dbo.Persons_Suffixes S ON P.SuffixID = S.SuffixID<br />
WHERE	PersonID = @PersonID</p>
<p>SET @FullName = dbo.Format_TitleCase(@LastName)</p>
<p>IF (isnull(@FirstName,&#8221;)  &#8221;) AND @FirstName  &#8216;The&#8217;<br />
	SET @FullName = @FullName + &#8216;, &#8216; + dbo.Format_TitleCase(@FirstName)</p>
<p>IF (isnull(@MiddleName,&#8221;)  &#8221;)<br />
	SET @FullName = @FullName + &#8216; &#8216; + dbo.Format_TitleCase(@MiddleName)</p>
<p>IF (isnull(@SuffixName,&#8221;)  &#8221;)<br />
	SET @FullName = @FullName + &#8216; &#8216; + @SuffixName</p>
<p>RETURN @FullName</p>
<p>END</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jonathan</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-52271</link>
		<dc:creator>Jonathan</dc:creator>
		<pubDate>Sat, 23 May 2009 17:25:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-52271</guid>
		<description>Markus - 
Your enhancements are great but you need to set @INDEX = 1 for mcclure to become McClure. I also added a line to eliminate but where if a word starts with a space it won&#039;t be capitalized.

Here is your code touched up
--------------------------------------------------------------------------
CREATE FUNCTION [dbo].[Format_TitleCase] (@InputString VARCHAR(4000) )

RETURNS VARCHAR(max)

AS

BEGIN --BEGIN1

DECLARE @Index INT
DECLARE @Char CHAR(1)
DECLARE @OutputString VARCHAR(max)
SET @InputString = LTRIM(RTRIM(@InputString)) --cures problem where string starts with blank space
SET @OutputString = LOWER(@InputString)
SET @Index = 1
SET @OutputString = STUFF(@OutputString, 1, 1,UPPER(SUBSTRING(@InputString,1,1)))
WHILE @Index &lt;= LEN(@InputString)
	BEGIN --BEGIN2
	SET @Char = SUBSTRING(@InputString, @Index, 1)
	IF @Char IN (&#039;m&#039;,&#039;M&#039;,&#039; &#039;, &#039;;&#039;, &#039;:&#039;, &#039;!&#039;, &#039;?&#039;, &#039;,&#039;, &#039;.&#039;, &#039;_&#039;, &#039;-&#039;, &#039;/&#039;, &#039;&amp;&#039;,&#039;&#039;&#039;&#039;,&#039;(&#039;,char(9))
		BEGIN --BEGIN3
		IF @Index + 1 &lt;= LEN(@InputString)
			BEGIN --BEGIN4
				IF @Char = &#039;&#039;&#039;&#039; AND UPPER(SUBSTRING(@InputString, @Index + 1, 1)) != &#039;S&#039;
					BEGIN
						--MAKE THE CHARACTER AFTER AN APOST UPPER UNLESS IT IS AN S. SO O&#039;NEIL WILL CASE CORRECTLY.
						SET @OutputString = STUFF(@OutputString, @Index + 1, 1,UPPER(SUBSTRING(@InputString, @Index + 1, 1)))
					END
				ELSE
					BEGIN
						IF UPPER(@Char) != &#039;M&#039;
							SET @OutputString = STUFF(@OutputString, @Index + 1, 1,UPPER(SUBSTRING(@InputString, @Index + 1, 1)))
					END

				IF UPPER(@Char) = &#039;M&#039; AND UPPER(SUBSTRING(@InputString, @Index + 1, 1)) = &#039;C&#039;
					BEGIN
						--MAKES THE C LOWER CASE.
						SET @OutputString = STUFF(@OutputString, @Index + 1, 1,LOWER(SUBSTRING(@InputString, @Index + 1, 1)))
						SET @OutputString = STUFF(@OutputString, @Index + 2, 1,UPPER(SUBSTRING(@InputString, @Index + 2, 1)))
						--WE TOOK CARE OF THE CHAR AFTER THE C, SO WE NEED TO ADVANCE.
						SET @Index = @Index + 1
					END
			END --END4
		END --END3

	SET @Index = @Index + 1
	
	END --END2

RETURN ISNULL(@OutputString,&#039;&#039;)

END --END1</description>
		<content:encoded><![CDATA[<p>Markus &#8211;<br />
Your enhancements are great but you need to set @INDEX = 1 for mcclure to become McClure. I also added a line to eliminate but where if a word starts with a space it won&#8217;t be capitalized.</p>
<p>Here is your code touched up<br />
&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;<br />
CREATE FUNCTION [dbo].[Format_TitleCase] (@InputString VARCHAR(4000) )</p>
<p>RETURNS VARCHAR(max)</p>
<p>AS</p>
<p>BEGIN &#8211;BEGIN1</p>
<p>DECLARE @Index INT<br />
DECLARE @Char CHAR(1)<br />
DECLARE @OutputString VARCHAR(max)<br />
SET @InputString = LTRIM(RTRIM(@InputString)) &#8211;cures problem where string starts with blank space<br />
SET @OutputString = LOWER(@InputString)<br />
SET @Index = 1<br />
SET @OutputString = STUFF(@OutputString, 1, 1,UPPER(SUBSTRING(@InputString,1,1)))<br />
WHILE @Index &lt;= LEN(@InputString)<br />
	BEGIN &#8211;BEGIN2<br />
	SET @Char = SUBSTRING(@InputString, @Index, 1)<br />
	IF @Char IN (&#039;m&#039;,&#039;M&#039;,&#039; &#039;, &#039;;&#039;, &#039;:&#039;, &#039;!&#039;, &#039;?&#039;, &#039;,&#039;, &#039;.&#039;, &#039;_&#039;, &#039;-&#039;, &#039;/&#039;, &#039;&amp;&#039;,&#039;&#039;&#039;&#039;,&#039;(&#039;,char(9))<br />
		BEGIN &#8211;BEGIN3<br />
		IF @Index + 1 &lt;= LEN(@InputString)<br />
			BEGIN &#8211;BEGIN4<br />
				IF @Char = &#039;&#039;&#039;&#039; AND UPPER(SUBSTRING(@InputString, @Index + 1, 1)) != &#039;S&#039;<br />
					BEGIN<br />
						&#8211;MAKE THE CHARACTER AFTER AN APOST UPPER UNLESS IT IS AN S. SO O&#039;NEIL WILL CASE CORRECTLY.<br />
						SET @OutputString = STUFF(@OutputString, @Index + 1, 1,UPPER(SUBSTRING(@InputString, @Index + 1, 1)))<br />
					END<br />
				ELSE<br />
					BEGIN<br />
						IF UPPER(@Char) != &#039;M&#039;<br />
							SET @OutputString = STUFF(@OutputString, @Index + 1, 1,UPPER(SUBSTRING(@InputString, @Index + 1, 1)))<br />
					END</p>
<p>				IF UPPER(@Char) = &#039;M&#039; AND UPPER(SUBSTRING(@InputString, @Index + 1, 1)) = &#039;C&#039;<br />
					BEGIN<br />
						&#8211;MAKES THE C LOWER CASE.<br />
						SET @OutputString = STUFF(@OutputString, @Index + 1, 1,LOWER(SUBSTRING(@InputString, @Index + 1, 1)))<br />
						SET @OutputString = STUFF(@OutputString, @Index + 2, 1,UPPER(SUBSTRING(@InputString, @Index + 2, 1)))<br />
						&#8211;WE TOOK CARE OF THE CHAR AFTER THE C, SO WE NEED TO ADVANCE.<br />
						SET @Index = @Index + 1<br />
					END<br />
			END &#8211;END4<br />
		END &#8211;END3</p>
<p>	SET @Index = @Index + 1</p>
<p>	END &#8211;END2</p>
<p>RETURN ISNULL(@OutputString,&#039;&#039;)</p>
<p>END &#8211;END1</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sachin Jain</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-49170</link>
		<dc:creator>Sachin Jain</dc:creator>
		<pubDate>Mon, 16 Mar 2009 05:49:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-49170</guid>
		<description>Thanks A lot. This helped me great dude.. Keep up the good work :)</description>
		<content:encoded><![CDATA[<p>Thanks A lot. This helped me great dude.. Keep up the good work :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQLAuthority News - Best Articles on SQLAuthority.com Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-47180</link>
		<dc:creator>SQLAuthority News - Best Articles on SQLAuthority.com Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Tue, 24 Feb 2009 12:06:35 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-47180</guid>
		<description>[...] SQL SERVER - UDF - Function to Convert Text String to Title Case - Proper Case [...]</description>
		<content:encoded><![CDATA[<p>[...] SQL SERVER &#8211; UDF &#8211; Function to Convert Text String to Title Case &#8211; Proper Case [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: hari</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-43971</link>
		<dc:creator>hari</dc:creator>
		<pubDate>Thu, 30 Oct 2008 10:31:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-43971</guid>
		<description>Please send me a procedure,
using 
case ,cast
and join conditions
 in an understanding manner
as like be

ex:
create procedure 
declare @in
set @int=.......
orderby
case when statments...(cast..

inner join etc...</description>
		<content:encoded><![CDATA[<p>Please send me a procedure,<br />
using<br />
case ,cast<br />
and join conditions<br />
 in an understanding manner<br />
as like be</p>
<p>ex:<br />
create procedure<br />
declare @in<br />
set @int=&#8230;&#8230;.<br />
orderby<br />
case when statments&#8230;(cast..</p>
<p>inner join etc&#8230;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Markus</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-43884</link>
		<dc:creator>Markus</dc:creator>
		<pubDate>Thu, 23 Oct 2008 20:37:26 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-43884</guid>
		<description>Pinal,
Here&#039;s an implementation that corrects the &quot;word part&quot; issue where it begins with an &quot;s&quot; and also catches the &quot;Mc&quot; part of a word to preserve the lowercase &quot;c&quot;.  Lastly, it uses VARCHAR(max) so that we no longer have to be concerned about the size of the text being converted. Thanks for sharing your base code.

create  FUNCTION udf_TitleCase (@InputString VARCHAR(max) )
RETURNS VARCHAR(max)
            AS
    BEGIN
    DECLARE @Index          INT
    DECLARE @Char           CHAR(1)
    DECLARE @OutputString   VARCHAR(max)
        SET @OutputString = LOWER(@InputString)
        SET @Index		  = 2
        SET @OutputString = STUFF(@OutputString, 1, 1,UPPER(SUBSTRING(@InputString,1,1)))

    WHILE @Index &lt;= LEN(@InputString)
	BEGIN
        SET @Char = SUBSTRING(@InputString, @Index, 1)
        
		IF @Char IN (&#039;m&#039;,&#039;M&#039;,&#039; &#039;, &#039;;&#039;, &#039;:&#039;, &#039;!&#039;, &#039;?&#039;, &#039;,&#039;, &#039;.&#039;, &#039;_&#039;, &#039;-&#039;, &#039;/&#039;, &#039;&amp;&#039;,&#039;&#039;&#039;&#039;,&#039;(&#039;,&#039;&#039;&#039;&#039;,char(9))
		BEGIN
            IF @Index + 1 &lt;= LEN(@InputString)
            BEGIN
				IF @Char = &#039;&#039;&#039;&#039; AND UPPER(SUBSTRING(@InputString, @Index + 1, 1)) != &#039;S&#039;
				BEGIN
					--MAKE THE CHARACTER AFTER AN APOST UPPER UNLESS IT IS AN S. SO O&#039;NEIL WILL CASE CORRECTLY.
					SET @OutputString = STUFF(@OutputString, @Index + 1, 1,UPPER(SUBSTRING(@InputString, @Index + 1, 1)))
				END
				ELSE
				BEGIN
					IF UPPER(@Char) != &#039;M&#039;
					BEGIN
						SET @OutputString = STUFF(@OutputString, @Index + 1, 1,UPPER(SUBSTRING(@InputString, @Index + 1, 1)))
					END
				END

				IF UPPER(@Char) = &#039;M&#039; AND UPPER(SUBSTRING(@InputString, @Index + 1, 1)) = &#039;C&#039;
				BEGIN
					--MAKES THE C LOWER CASE.
					SET @OutputString = STUFF(@OutputString, @Index + 1, 1,LOWER(SUBSTRING(@InputString, @Index + 1, 1)))
					SET @OutputString = STUFF(@OutputString, @Index + 2, 1,UPPER(SUBSTRING(@InputString, @Index + 2, 1)))
					--WE TOOK CARE OF THE CHAR AFTER THE C, SO WE NEED TO ADVANCE.
					SET @Index = @Index + 1
				END

			END
	END

    SET @Index = @Index + 1
    END

RETURN ISNULL(@OutputString,&#039;&#039;)
END</description>
		<content:encoded><![CDATA[<p>Pinal,<br />
Here&#8217;s an implementation that corrects the &#8220;word part&#8221; issue where it begins with an &#8220;s&#8221; and also catches the &#8220;Mc&#8221; part of a word to preserve the lowercase &#8220;c&#8221;.  Lastly, it uses VARCHAR(max) so that we no longer have to be concerned about the size of the text being converted. Thanks for sharing your base code.</p>
<p>create  FUNCTION udf_TitleCase (@InputString VARCHAR(max) )<br />
RETURNS VARCHAR(max)<br />
            AS<br />
    BEGIN<br />
    DECLARE @Index          INT<br />
    DECLARE @Char           CHAR(1)<br />
    DECLARE @OutputString   VARCHAR(max)<br />
        SET @OutputString = LOWER(@InputString)<br />
        SET @Index		  = 2<br />
        SET @OutputString = STUFF(@OutputString, 1, 1,UPPER(SUBSTRING(@InputString,1,1)))</p>
<p>    WHILE @Index &lt;= LEN(@InputString)<br />
	BEGIN<br />
        SET @Char = SUBSTRING(@InputString, @Index, 1)</p>
<p>		IF @Char IN (&#8216;m&#8217;,'M&#8217;,&#8217; &#8216;, &#8216;;&#8217;, &#8216;:&#8217;, &#8216;!&#8217;, &#8216;?&#8217;, &#8216;,&#8217;, &#8216;.&#8217;, &#8216;_&#8217;, &#8216;-&#8217;, &#8216;/&#8217;, &#8216;&amp;&#8217;,&#8221;&#8221;,&#8217;(&#8216;,&#8221;&#8221;,char(9))<br />
		BEGIN<br />
            IF @Index + 1 &lt;= LEN(@InputString)<br />
            BEGIN<br />
				IF @Char = &#8221;&#8221; AND UPPER(SUBSTRING(@InputString, @Index + 1, 1)) != &#8216;S&#8217;<br />
				BEGIN<br />
					&#8211;MAKE THE CHARACTER AFTER AN APOST UPPER UNLESS IT IS AN S. SO O&#8217;NEIL WILL CASE CORRECTLY.<br />
					SET @OutputString = STUFF(@OutputString, @Index + 1, 1,UPPER(SUBSTRING(@InputString, @Index + 1, 1)))<br />
				END<br />
				ELSE<br />
				BEGIN<br />
					IF UPPER(@Char) != &#8216;M&#8217;<br />
					BEGIN<br />
						SET @OutputString = STUFF(@OutputString, @Index + 1, 1,UPPER(SUBSTRING(@InputString, @Index + 1, 1)))<br />
					END<br />
				END</p>
<p>				IF UPPER(@Char) = &#8216;M&#8217; AND UPPER(SUBSTRING(@InputString, @Index + 1, 1)) = &#8216;C&#8217;<br />
				BEGIN<br />
					&#8211;MAKES THE C LOWER CASE.<br />
					SET @OutputString = STUFF(@OutputString, @Index + 1, 1,LOWER(SUBSTRING(@InputString, @Index + 1, 1)))<br />
					SET @OutputString = STUFF(@OutputString, @Index + 2, 1,UPPER(SUBSTRING(@InputString, @Index + 2, 1)))<br />
					&#8211;WE TOOK CARE OF THE CHAR AFTER THE C, SO WE NEED TO ADVANCE.<br />
					SET @Index = @Index + 1<br />
				END</p>
<p>			END<br />
	END</p>
<p>    SET @Index = @Index + 1<br />
    END</p>
<p>RETURN ISNULL(@OutputString,&#8221;)<br />
END</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Clive</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-42675</link>
		<dc:creator>Clive</dc:creator>
		<pubDate>Thu, 11 Sep 2008 04:28:37 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-42675</guid>
		<description>Many, many thanks for this Pinal, you&#039;ve saved me a heap of time.</description>
		<content:encoded><![CDATA[<p>Many, many thanks for this Pinal, you&#8217;ve saved me a heap of time.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: SQL SERVER - UDF - Function to Convert Text String to Title Case - Proper Case - Part 2 Journey to SQL Authority with Pinal Dave</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-41893</link>
		<dc:creator>SQL SERVER - UDF - Function to Convert Text String to Title Case - Proper Case - Part 2 Journey to SQL Authority with Pinal Dave</dc:creator>
		<pubDate>Fri, 22 Aug 2008 01:31:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-41893</guid>
		<description>[...] 22, 2008 by pinaldave    I had previously written SQL SERVER - UDF - Function to Convert Text String to Title Case - Proper Case and I had really enjoyed writing it. Above script converts first letter of each word from sentence [...]</description>
		<content:encoded><![CDATA[<p>[...] 22, 2008 by pinaldave    I had previously written SQL SERVER &#8211; UDF &#8211; Function to Convert Text String to Title Case &#8211; Proper Case and I had really enjoyed writing it. Above script converts first letter of each word from sentence [...]</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lundi Matoti</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-41751</link>
		<dc:creator>Lundi Matoti</dc:creator>
		<pubDate>Mon, 18 Aug 2008 08:34:49 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-41751</guid>
		<description>I have a slight problem. I am trying to convert the names of people into a combination of proper and title case. The function works for almost all of them except in cases where there are initials like &quot;MC&quot; (it works for &quot;M.C.&quot;) or a name and initials written like &quot;JOHN TJ or TJ JOHN&quot;. I need a modified function which can leave MC as MC and not Mc and JOHN TJ (TJ JOHN) as John TJ (TJ John) and not John Tj (Tj John). Can you help?</description>
		<content:encoded><![CDATA[<p>I have a slight problem. I am trying to convert the names of people into a combination of proper and title case. The function works for almost all of them except in cases where there are initials like &#8220;MC&#8221; (it works for &#8220;M.C.&#8221;) or a name and initials written like &#8220;JOHN TJ or TJ JOHN&#8221;. I need a modified function which can leave MC as MC and not Mc and JOHN TJ (TJ JOHN) as John TJ (TJ John) and not John Tj (Tj John). Can you help?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rek</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-41673</link>
		<dc:creator>Rek</dc:creator>
		<pubDate>Thu, 14 Aug 2008 09:04:14 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-41673</guid>
		<description>hi,
Thank you very much.
you save my lots of time.
Your work is excellent.
you are genius.</description>
		<content:encoded><![CDATA[<p>hi,<br />
Thank you very much.<br />
you save my lots of time.<br />
Your work is excellent.<br />
you are genius.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: artman</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-41555</link>
		<dc:creator>artman</dc:creator>
		<pubDate>Mon, 11 Aug 2008 05:40:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-41555</guid>
		<description>thk alot sir</description>
		<content:encoded><![CDATA[<p>thk alot sir</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Louis</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-39449</link>
		<dc:creator>Louis</dc:creator>
		<pubDate>Mon, 23 Jun 2008 19:21:10 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-39449</guid>
		<description>I too got errors, I realized when you cut and past for some reason some of the quotes (&#039;) come over as different characters.  Just delete them and type in the proper quotes.

Also I changed the this line

IF @Char != ””
OR
UPPER(SUBSTRING(@InputString, @Index + 1, 1))
!= ‘S’

to the following to fix the function

IF @Char != &#039;&#039;
OR
UPPER(SUBSTRING(@InputString, @Index + 1, 1))
!= &#039; &#039;</description>
		<content:encoded><![CDATA[<p>I too got errors, I realized when you cut and past for some reason some of the quotes (&#8216;) come over as different characters.  Just delete them and type in the proper quotes.</p>
<p>Also I changed the this line</p>
<p>IF @Char != ””<br />
OR<br />
UPPER(SUBSTRING(@InputString, @Index + 1, 1))<br />
!= ‘S’</p>
<p>to the following to fix the function</p>
<p>IF @Char != &#8221;<br />
OR<br />
UPPER(SUBSTRING(@InputString, @Index + 1, 1))<br />
!= &#8216; &#8216;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Subh</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-39431</link>
		<dc:creator>Subh</dc:creator>
		<pubDate>Mon, 23 Jun 2008 06:14:34 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-39431</guid>
		<description>Hi i have tried your function but getting the following errors
Msg 102, Level 15, State 1, Procedure udf_TitleCase, Line 16
Incorrect syntax near &#039;’&#039;.
Msg 102, Level 15, State 1, Procedure udf_TitleCase, Line 19
Incorrect syntax near &#039;”&#039;.
Msg 102, Level 15, State 1, Procedure udf_TitleCase, Line 29
Incorrect syntax near &#039;”&#039;.

Could u tell me what are the necessary changes i have to make?
My function is the same as below:

CREATE FUNCTION udf_TitleCase (@InputString VARCHAR(4000) ) 
RETURNS VARCHAR(4000)
            AS
    BEGIN
    DECLARE @Index          INT
    DECLARE @Char           CHAR(1)
    DECLARE @OutputString   VARCHAR(255)
        SET @OutputString = LOWER(@InputString)
        SET @Index = 2
        SET @OutputString =
                STUFF(@OutputString, 1, 1,UPPER(SUBSTRING(@InputString,1,1)))
    WHILE @Index &lt;= LEN(@InputString)
        BEGIN
        SET @Char = SUBSTRING(@InputString, @Index, 1)
        IF @Char IN (’ ‘, ‘;’, ‘:’, ‘!’, ‘?’, ‘,’, ‘.’, ‘_’, ‘-’, ‘/’, ‘&amp;’,””, ‘(’, char(9))
            IF @Index + 1 &lt;= LEN(@InputString)
            BEGIN
            IF @Char != ”” 
                        OR
                        UPPER(SUBSTRING(@InputString, @Index + 1, 1))
                        != ‘S’
            SET @OutputString =
                        STUFF(@OutputString, @Index + 1, 1,UPPER(SUBSTRING(@InputString, @Index
                                    + 1, 1)))
            END
        SET @Index = @Index + 1
        END
    RETURN ISNULL(@OutputString,”)
    END
GO</description>
		<content:encoded><![CDATA[<p>Hi i have tried your function but getting the following errors<br />
Msg 102, Level 15, State 1, Procedure udf_TitleCase, Line 16<br />
Incorrect syntax near &#8216;’&#8217;.<br />
Msg 102, Level 15, State 1, Procedure udf_TitleCase, Line 19<br />
Incorrect syntax near &#8216;”&#8217;.<br />
Msg 102, Level 15, State 1, Procedure udf_TitleCase, Line 29<br />
Incorrect syntax near &#8216;”&#8217;.</p>
<p>Could u tell me what are the necessary changes i have to make?<br />
My function is the same as below:</p>
<p>CREATE FUNCTION udf_TitleCase (@InputString VARCHAR(4000) )<br />
RETURNS VARCHAR(4000)<br />
            AS<br />
    BEGIN<br />
    DECLARE @Index          INT<br />
    DECLARE @Char           CHAR(1)<br />
    DECLARE @OutputString   VARCHAR(255)<br />
        SET @OutputString = LOWER(@InputString)<br />
        SET @Index = 2<br />
        SET @OutputString =<br />
                STUFF(@OutputString, 1, 1,UPPER(SUBSTRING(@InputString,1,1)))<br />
    WHILE @Index &lt;= LEN(@InputString)<br />
        BEGIN<br />
        SET @Char = SUBSTRING(@InputString, @Index, 1)<br />
        IF @Char IN (’ ‘, ‘;’, ‘:’, ‘!’, ‘?’, ‘,’, ‘.’, ‘_’, ‘-’, ‘/’, ‘&amp;’,””, ‘(’, char(9))<br />
            IF @Index + 1 &lt;= LEN(@InputString)<br />
            BEGIN<br />
            IF @Char != ””<br />
                        OR<br />
                        UPPER(SUBSTRING(@InputString, @Index + 1, 1))<br />
                        != ‘S’<br />
            SET @OutputString =<br />
                        STUFF(@OutputString, @Index + 1, 1,UPPER(SUBSTRING(@InputString, @Index<br />
                                    + 1, 1)))<br />
            END<br />
        SET @Index = @Index + 1<br />
        END<br />
    RETURN ISNULL(@OutputString,”)<br />
    END<br />
GO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Karnati</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-38952</link>
		<dc:creator>Karnati</dc:creator>
		<pubDate>Tue, 03 Jun 2008 16:01:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-38952</guid>
		<description>The statement in the top didn&#039;t gave the results as stated. 

Run Following T-SQL statement in query analyzer:

SELECT dbo.udf_TitleCase(‘This function will convert this string to title
 case!’)
            
The output will be displayed in Results pan as follows:

This Function Will Convert This String To Title Case!

But, it gave as &quot;This Function Will Convert This string To Title Case!&quot;. See the word &quot;string&quot; is not title case.

After debugging, I REMOVED the line mentioned below and it works fine for me.

IF @Char != ””
OR
UPPER(SUBSTRING(@InputString, @Index + 1, 1))
!= ‘S’

Anyways, thank you very much Pinal for saving my time.</description>
		<content:encoded><![CDATA[<p>The statement in the top didn&#8217;t gave the results as stated. </p>
<p>Run Following T-SQL statement in query analyzer:</p>
<p>SELECT dbo.udf_TitleCase(‘This function will convert this string to title<br />
 case!’)</p>
<p>The output will be displayed in Results pan as follows:</p>
<p>This Function Will Convert This String To Title Case!</p>
<p>But, it gave as &#8220;This Function Will Convert This string To Title Case!&#8221;. See the word &#8220;string&#8221; is not title case.</p>
<p>After debugging, I REMOVED the line mentioned below and it works fine for me.</p>
<p>IF @Char != ””<br />
OR<br />
UPPER(SUBSTRING(@InputString, @Index + 1, 1))<br />
!= ‘S’</p>
<p>Anyways, thank you very much Pinal for saving my time.</p>
]]></content:encoded>
	</item>
</channel>
</rss>
