<?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>Personal Notes of Pinal Dave</description>
	<lastBuildDate>Fri, 10 Feb 2012 05:05:02 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
	<item>
		<title>By: Hafiz</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-208019</link>
		<dc:creator><![CDATA[Hafiz]]></dc:creator>
		<pubDate>Wed, 30 Nov 2011 14:37:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-208019</guid>
		<description><![CDATA[This is fantastic and was very much useful in my case. Thanks.

Hafiz]]></description>
		<content:encoded><![CDATA[<p>This is fantastic and was very much useful in my case. Thanks.</p>
<p>Hafiz</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: NabyL</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-195958</link>
		<dc:creator><![CDATA[NabyL]]></dc:creator>
		<pubDate>Tue, 15 Nov 2011 10:07:43 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-195958</guid>
		<description><![CDATA[This what i tried on my Database but unluckily received an error that states:
&quot;Msg 102, Level 15, State 1, Procedure ChangeTitleCase, Line 26
Incorrect syntax near &#039;)&#039;.&quot;

Please guide!!
---------------------------------------------------------------------------------

CREATE FUNCTION ChangeTitleCase (@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 (&#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;)
IF @Index + 1 &lt;= LEN(@InputString)
BEGIN
IF @Char != &#039;&#039;&#039;&#039;
OR
UPPER(SUBSTRING(@InputString, @Index + 1, 1)) != &#039;S&#039;
SET @OutputString =
STUFF(@OutputString, @Index + 1, 1,UPPER(SUBSTRING(@InputString, @Index + 1, 1)))
END
SET @Index = @Index + 1
END
RETURN ISNULL(@OutputString,&#039;&#039;)]]></description>
		<content:encoded><![CDATA[<p>This what i tried on my Database but unluckily received an error that states:<br />
&#8220;Msg 102, Level 15, State 1, Procedure ChangeTitleCase, Line 26<br />
Incorrect syntax near &#8216;)&#8217;.&#8221;</p>
<p>Please guide!!<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;&#8212;&#8212;&#8212;</p>
<p>CREATE FUNCTION ChangeTitleCase (@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 (&#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;)<br />
IF @Index + 1 &lt;= LEN(@InputString)<br />
BEGIN<br />
IF @Char != &#039;&#039;&#039;&#039;<br />
OR<br />
UPPER(SUBSTRING(@InputString, @Index + 1, 1)) != &#039;S&#039;<br />
SET @OutputString =<br />
STUFF(@OutputString, @Index + 1, 1,UPPER(SUBSTRING(@InputString, @Index + 1, 1)))<br />
END<br />
SET @Index = @Index + 1<br />
END<br />
RETURN ISNULL(@OutputString,&#039;&#039;)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Lee Cumbie</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-195532</link>
		<dc:creator><![CDATA[Lee Cumbie]]></dc:creator>
		<pubDate>Mon, 14 Nov 2011 21:07:42 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-195532</guid>
		<description><![CDATA[What is the option if you want to actually update the permanent table?]]></description>
		<content:encoded><![CDATA[<p>What is the option if you want to actually update the permanent table?</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ahmed Hassan</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-183207</link>
		<dc:creator><![CDATA[Ahmed Hassan]]></dc:creator>
		<pubDate>Tue, 25 Oct 2011 05:43:30 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-183207</guid>
		<description><![CDATA[Thanx, this is so much helpful to me!!]]></description>
		<content:encoded><![CDATA[<p>Thanx, this is so much helpful to me!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mamun Reza</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-181118</link>
		<dc:creator><![CDATA[Mamun Reza]]></dc:creator>
		<pubDate>Thu, 20 Oct 2011 09:58:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-181118</guid>
		<description><![CDATA[Hi, thanks a lot for this helpful script. :)]]></description>
		<content:encoded><![CDATA[<p>Hi, thanks a lot for this helpful script. :)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Sam Soh</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-173914</link>
		<dc:creator><![CDATA[Sam Soh]]></dc:creator>
		<pubDate>Sat, 01 Oct 2011 15:00:15 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-173914</guid>
		<description><![CDATA[Your script has saved my life!!!! Thank you very much!!!]]></description>
		<content:encoded><![CDATA[<p>Your script has saved my life!!!! Thank you very much!!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Elton</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-171021</link>
		<dc:creator><![CDATA[Elton]]></dc:creator>
		<pubDate>Fri, 23 Sep 2011 21:43:32 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-171021</guid>
		<description><![CDATA[Perfect function. Just copy and paste into SQL Server Management, compile and no more! Tks.]]></description>
		<content:encoded><![CDATA[<p>Perfect function. Just copy and paste into SQL Server Management, compile and no more! Tks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: JIKEN</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-143452</link>
		<dc:creator><![CDATA[JIKEN]]></dc:creator>
		<pubDate>Fri, 24 Jun 2011 18:04:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-143452</guid>
		<description><![CDATA[Super duper function sir
:)]]></description>
		<content:encoded><![CDATA[<p>Super duper function sir<br />
:)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rafal Ziolkowski</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-136195</link>
		<dc:creator><![CDATA[Rafal Ziolkowski]]></dc:creator>
		<pubDate>Mon, 23 May 2011 10:52:17 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-136195</guid>
		<description><![CDATA[Thanks for sharing!

I have only one remark here. I think you should declare @OutputString as VARCHAR(4000) as well. Otherwise you will loose string content over 255 chars.]]></description>
		<content:encoded><![CDATA[<p>Thanks for sharing!</p>
<p>I have only one remark here. I think you should declare @OutputString as VARCHAR(4000) as well. Otherwise you will loose string content over 255 chars.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-96245</link>
		<dc:creator><![CDATA[madhivanan]]></dc:creator>
		<pubDate>Thu, 28 Oct 2010 07:43:12 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-96245</guid>
		<description><![CDATA[InitCap does not matter when you write queries until your database has a case sensitive coolation]]></description>
		<content:encoded><![CDATA[<p>InitCap does not matter when you write queries until your database has a case sensitive coolation</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Abdul Rahman</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-96045</link>
		<dc:creator><![CDATA[Abdul Rahman]]></dc:creator>
		<pubDate>Wed, 27 Oct 2010 04:56:57 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-96045</guid>
		<description><![CDATA[Hi

i have a question regarding this udf. English language specific the words like and, or, the are not marked as init cap, how can we handle it?

thanks in advance:
Abdul Rahman Khokhar]]></description>
		<content:encoded><![CDATA[<p>Hi</p>
<p>i have a question regarding this udf. English language specific the words like and, or, the are not marked as init cap, how can we handle it?</p>
<p>thanks in advance:<br />
Abdul Rahman Khokhar</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-89729</link>
		<dc:creator><![CDATA[Madhivanan]]></dc:creator>
		<pubDate>Mon, 27 Sep 2010 11:17:02 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-89729</guid>
		<description><![CDATA[You can user PRE tag when you post code]]></description>
		<content:encoded><![CDATA[<p>You can user PRE tag when you post code</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Moden</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-89491</link>
		<dc:creator><![CDATA[Jeff Moden]]></dc:creator>
		<pubDate>Sun, 26 Sep 2010 03:24:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-89491</guid>
		<description><![CDATA[Heh... and I really hate moderated forums. ;-)]]></description>
		<content:encoded><![CDATA[<p>Heh&#8230; and I really hate moderated forums. ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Moden</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-89490</link>
		<dc:creator><![CDATA[Jeff Moden]]></dc:creator>
		<pubDate>Sun, 26 Sep 2010 03:23:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-89490</guid>
		<description><![CDATA[Heh... like I said... the forum doesn&#039;t honor ANY formatting... not even non-breaking spaces.  The code really looks ugly compared to the original.  My apologies but theres not much I can do about it.]]></description>
		<content:encoded><![CDATA[<p>Heh&#8230; like I said&#8230; the forum doesn&#8217;t honor ANY formatting&#8230; not even non-breaking spaces.  The code really looks ugly compared to the original.  My apologies but theres not much I can do about it.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Jeff Moden</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-89489</link>
		<dc:creator><![CDATA[Jeff Moden]]></dc:creator>
		<pubDate>Sun, 26 Sep 2010 03:20:59 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-89489</guid>
		<description><![CDATA[Howdy.  Nicely done.  Thought I&#039;d throw my own 2 cents in here.  The following is about the fastest InitialCaps function I&#039;ve found and it will put a cap after just about anything that isn&#039;t a letter including special characters.  Heh... it&#039;s remarkably simple, too!  The original author (George Mastros) had one heck of an idea on this one!  It even beats a Tally Table solution.

It&#039;s a shame this forum doesn&#039;t honor any type of formatting... the function looks quite nice when properly formatted.  I&#039;m trying to us non-breaking spaces but, if that doesn&#039;t work, I&#039;ll just post it flat...

CREATE FUNCTION dbo.InitialCap(@String VARCHAR(8000))
/***************************************************************************************************
 Purpose:
 Capitalize any lower case alpha character which follows any non alpha character or single quote.

 Revision History:
 Rev 00 - 24 Feb 2010 - George Mastros - Initial concept
 http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/sql-server-proper-case-function

 Rev 01 - 25 Sep 2010 - Jeff Moden 
        - Redaction for personal use and added documentation.
        - Add no-cap single-quote by single-quote to the filter.
***************************************************************************************************/
RETURNS VARCHAR(8000)
     AS
  BEGIN 
----------------------------------------------------------------------------------------------------
DECLARE @Position INT
;
--===== Update the first character no matter what and then find the next postionthat we 
     -- need to update.  The collation here is essential to making this so simple.
     -- A-z is equivalent to the slower A-Z
 SELECT @String   = STUFF(LOWER(@String),1,1,UPPER(LEFT(@String,1))),
        @Position = PATINDEX(&#039;%[^A-Za-z&#039;&#039;][a-z]%&#039;,@String COLLATE Latin1_General_Bin)
;
--===== Do the same thing over and over until we run out of places to capitalize.
     -- Note the reason for the speed here is that ONLY places that need capitalization
     -- are even considered for @Position using the speed of PATINDEX. 
  WHILE @Position &gt; 0
 SELECT @String   = STUFF(@String,@Position,2,UPPER(SUBSTRING(@String,@Position,2))),
        @Position = PATINDEX(&#039;%[^A-Za-z&#039;&#039;][a-z]%&#039;,@String COLLATE Latin1_General_Bin)
;
----------------------------------------------------------------------------------------------------
 RETURN @String;
    END ;]]></description>
		<content:encoded><![CDATA[<p>Howdy.  Nicely done.  Thought I&#8217;d throw my own 2 cents in here.  The following is about the fastest InitialCaps function I&#8217;ve found and it will put a cap after just about anything that isn&#8217;t a letter including special characters.  Heh&#8230; it&#8217;s remarkably simple, too!  The original author (George Mastros) had one heck of an idea on this one!  It even beats a Tally Table solution.</p>
<p>It&#8217;s a shame this forum doesn&#8217;t honor any type of formatting&#8230; the function looks quite nice when properly formatted.  I&#8217;m trying to us non-breaking spaces but, if that doesn&#8217;t work, I&#8217;ll just post it flat&#8230;</p>
<p>CREATE FUNCTION dbo.InitialCap(@String VARCHAR(8000))<br />
/***************************************************************************************************<br />
 Purpose:<br />
 Capitalize any lower case alpha character which follows any non alpha character or single quote.</p>
<p> Revision History:<br />
 Rev 00 &#8211; 24 Feb 2010 &#8211; George Mastros &#8211; Initial concept<br />
 <a href="http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/sql-server-proper-case-function" rel="nofollow">http://blogs.lessthandot.com/index.php/DataMgmt/DBProgramming/sql-server-proper-case-function</a></p>
<p> Rev 01 &#8211; 25 Sep 2010 &#8211; Jeff Moden<br />
        &#8211; Redaction for personal use and added documentation.<br />
        &#8211; Add no-cap single-quote by single-quote to the filter.<br />
***************************************************************************************************/<br />
RETURNS VARCHAR(8000)<br />
     AS<br />
  BEGIN<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;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
DECLARE @Position INT<br />
;<br />
&#8211;===== Update the first character no matter what and then find the next postionthat we<br />
     &#8212; need to update.  The collation here is essential to making this so simple.<br />
     &#8212; A-z is equivalent to the slower A-Z<br />
 SELECT @String   = STUFF(LOWER(@String),1,1,UPPER(LEFT(@String,1))),<br />
        @Position = PATINDEX(&#8216;%[^A-Za-z''][a-z]%&#8217;,@String COLLATE Latin1_General_Bin)<br />
;<br />
&#8211;===== Do the same thing over and over until we run out of places to capitalize.<br />
     &#8212; Note the reason for the speed here is that ONLY places that need capitalization<br />
     &#8212; are even considered for @Position using the speed of PATINDEX.<br />
  WHILE @Position &gt; 0<br />
 SELECT @String   = STUFF(@String,@Position,2,UPPER(SUBSTRING(@String,@Position,2))),<br />
        @Position = PATINDEX(&#8216;%[^A-Za-z''][a-z]%&#8217;,@String COLLATE Latin1_General_Bin)<br />
;<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;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
 RETURN @String;<br />
    END ;</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-88499</link>
		<dc:creator><![CDATA[Madhivanan]]></dc:creator>
		<pubDate>Mon, 20 Sep 2010 14:43:52 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-88499</guid>
		<description><![CDATA[Refer this to know to how to use single quotes effectively in SQL Server
http://beyondrelational.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx]]></description>
		<content:encoded><![CDATA[<p>Refer this to know to how to use single quotes effectively in SQL Server<br />
<a href="http://beyondrelational.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx" rel="nofollow">http://beyondrelational.com/blogs/madhivanan/archive/2008/02/19/understanding-single-quotes.aspx</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Rod</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-88360</link>
		<dc:creator><![CDATA[Rod]]></dc:creator>
		<pubDate>Sun, 19 Sep 2010 18:52:23 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-88360</guid>
		<description><![CDATA[Jonathan.... Great work and many thanks.

I still have trouble with the apostrophe &#039;S though.

It doesn&#039;t seem to be recognizing the != &#039;S&#039; because: 

O&#039;NEILL&#039;S FURN GALLERY returns O&#039;Neill&#039;S Furn Gallery
and
ALEXANDRA&#039;S returns Alexandra&#039;S 

Any ideas would be greatly appreciated because I have many more apostrophe S&#039;s than O&#039;Neil&#039;s

Thanks
Rod

----------------------------------------------------------------
CREATE FUNCTION dbo.udf_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

GO]]></description>
		<content:encoded><![CDATA[<p>Jonathan&#8230;. Great work and many thanks.</p>
<p>I still have trouble with the apostrophe &#8216;S though.</p>
<p>It doesn&#8217;t seem to be recognizing the != &#8216;S&#8217; because: </p>
<p>O&#8217;NEILL&#8217;S FURN GALLERY returns O&#8217;Neill&#8217;S Furn Gallery<br />
and<br />
ALEXANDRA&#8217;S returns Alexandra&#8217;S </p>
<p>Any ideas would be greatly appreciated because I have many more apostrophe S&#8217;s than O&#8217;Neil&#8217;s</p>
<p>Thanks<br />
Rod</p>
<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<br />
CREATE FUNCTION dbo.udf_TitleCase<br />
(@InputString VARCHAR(4000) )<br />
RETURNS VARCHAR(max)<br />
AS<br />
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>
<p>GO</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ganesh</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-85347</link>
		<dc:creator><![CDATA[Ganesh]]></dc:creator>
		<pubDate>Thu, 26 Aug 2010 14:42:11 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-85347</guid>
		<description><![CDATA[Thanks buddy. Good work.]]></description>
		<content:encoded><![CDATA[<p>Thanks buddy. Good work.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-81695</link>
		<dc:creator><![CDATA[Madhivanan]]></dc:creator>
		<pubDate>Mon, 26 Jul 2010 08:23:04 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-81695</guid>
		<description><![CDATA[There is not tool. However you can use some sql-beatifier. Search for the same in google/bing]]></description>
		<content:encoded><![CDATA[<p>There is not tool. However you can use some sql-beatifier. Search for the same in google/bing</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mehul</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-81657</link>
		<dc:creator><![CDATA[Mehul]]></dc:creator>
		<pubDate>Sun, 25 Jul 2010 20:36:06 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-81657</guid>
		<description><![CDATA[Hi,

   Is there any function which convert only KEYWORDS in upper case from stored procedure?


Mehul]]></description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>   Is there any function which convert only KEYWORDS in upper case from stored procedure?</p>
<p>Mehul</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Gimhan</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-78659</link>
		<dc:creator><![CDATA[Gimhan]]></dc:creator>
		<pubDate>Sat, 03 Jul 2010 12:24:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-78659</guid>
		<description><![CDATA[Thanks Guru.. You made my day so beautiful and easy. Appreciate your good work. Keep it up..]]></description>
		<content:encoded><![CDATA[<p>Thanks Guru.. You made my day so beautiful and easy. Appreciate your good work. Keep it up..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-63789</link>
		<dc:creator><![CDATA[Madhivanan]]></dc:creator>
		<pubDate>Fri, 26 Mar 2010 09:37:08 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-63789</guid>
		<description><![CDATA[Joe Celko&#039;s solution can further be simplied to


declare @Foobar table(data varchar(1000))
insert into @Foobar
select &#039;this is only for testing&#039; union all
select &#039;SEe if This workS well&#039; union all
select &#039;TESTING DATA&#039;
/*
Original data
*/
select * from @Foobar

/*
Modified data
*/

select 
ltrim
(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
replace(
(LOWER (&#039; &#039;+data))
,&#039; a&#039;,&#039; A&#039;)
,&#039; b&#039;,&#039; B&#039;)
,&#039; c&#039;,&#039; C&#039;)
,&#039; d&#039;,&#039; D&#039;)
,&#039; e&#039;,&#039; E&#039;)
,&#039; f&#039;,&#039; F&#039;)
,&#039; g&#039;,&#039; G&#039;)
,&#039; h&#039;,&#039; H&#039;)
,&#039; i&#039;,&#039; I&#039;)
,&#039; j&#039;,&#039; J&#039;)
,&#039; k&#039;,&#039; K&#039;)
,&#039; l&#039;,&#039; L&#039;)
,&#039; m&#039;,&#039; M&#039;)
,&#039; n&#039;,&#039; N&#039;)
,&#039; o&#039;,&#039; O&#039;)
,&#039; p&#039;,&#039; P&#039;)
,&#039; q&#039;,&#039; Q&#039;)
,&#039; r&#039;,&#039; R&#039;)
,&#039; s&#039;,&#039; S&#039;)
,&#039; t&#039;,&#039; T&#039;)
,&#039; u&#039;,&#039; U&#039;)
,&#039; v&#039;,&#039; V&#039;)
,&#039; w&#039;,&#039; W&#039;)
,&#039; x&#039;,&#039; X&#039;)
,&#039; y&#039;,&#039; Y&#039;)
,&#039; x&#039;,&#039; Z&#039;)
) AS data
from @Foobar]]></description>
		<content:encoded><![CDATA[<p>Joe Celko&#8217;s solution can further be simplied to</p>
<p>declare @Foobar table(data varchar(1000))<br />
insert into @Foobar<br />
select &#39;this is only for testing&#39; union all<br />
select &#39;SEe if This workS well&#39; union all<br />
select &#39;TESTING DATA&#39;<br />
/*<br />
Original data<br />
*/<br />
select * from @Foobar</p>
<p>/*<br />
Modified data<br />
*/</p>
<p>select<br />
ltrim<br />
(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
replace(<br />
(LOWER (&#39; &#39;+data))<br />
,&#39; a&#39;,&#39; A&#39;)<br />
,&#39; b&#39;,&#39; B&#39;)<br />
,&#39; c&#39;,&#39; C&#39;)<br />
,&#39; d&#39;,&#39; D&#39;)<br />
,&#39; e&#39;,&#39; E&#39;)<br />
,&#39; f&#39;,&#39; F&#39;)<br />
,&#39; g&#39;,&#39; G&#39;)<br />
,&#39; h&#39;,&#39; H&#39;)<br />
,&#39; i&#39;,&#39; I&#39;)<br />
,&#39; j&#39;,&#39; J&#39;)<br />
,&#39; k&#39;,&#39; K&#39;)<br />
,&#39; l&#39;,&#39; L&#39;)<br />
,&#39; m&#39;,&#39; M&#39;)<br />
,&#39; n&#39;,&#39; N&#39;)<br />
,&#39; o&#39;,&#39; O&#39;)<br />
,&#39; p&#39;,&#39; P&#39;)<br />
,&#39; q&#39;,&#39; Q&#39;)<br />
,&#39; r&#39;,&#39; R&#39;)<br />
,&#39; s&#39;,&#39; S&#39;)<br />
,&#39; t&#39;,&#39; T&#39;)<br />
,&#39; u&#39;,&#39; U&#39;)<br />
,&#39; v&#39;,&#39; V&#39;)<br />
,&#39; w&#39;,&#39; W&#39;)<br />
,&#39; x&#39;,&#39; X&#39;)<br />
,&#39; y&#39;,&#39; Y&#39;)<br />
,&#39; x&#39;,&#39; Z&#39;)<br />
) AS data<br />
from @Foobar</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Madhivanan</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-63788</link>
		<dc:creator><![CDATA[Madhivanan]]></dc:creator>
		<pubDate>Fri, 26 Mar 2010 09:08:22 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-63788</guid>
		<description><![CDATA[Note the last part of the function

RETURN ISNULL(@OutputString,&#039;&#039;)

If the input is null, it actually change it to empty string

So either modify that line to

RETURN @OutputString

or

change your SELECT to


select
isnull(nullif(dbo.udf_TitleCase(t.column),&#039;&#039;),&#039;Undefined&#039;) as AliasColumn
from
table as t]]></description>
		<content:encoded><![CDATA[<p>Note the last part of the function</p>
<p>RETURN ISNULL(@OutputString,&#39;&#39;)</p>
<p>If the input is null, it actually change it to empty string</p>
<p>So either modify that line to</p>
<p>RETURN @OutputString</p>
<p>or</p>
<p>change your SELECT to</p>
<p>select<br />
isnull(nullif(dbo.udf_TitleCase(t.column),&#39;&#39;),&#39;Undefined&#39;) as AliasColumn<br />
from<br />
table as t</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Manish Chouhan</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-60363</link>
		<dc:creator><![CDATA[Manish Chouhan]]></dc:creator>
		<pubDate>Fri, 29 Jan 2010 06:48:13 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-60363</guid>
		<description><![CDATA[thnx dude U gave me a very nice block of code and saved my time..........]]></description>
		<content:encoded><![CDATA[<p>thnx dude U gave me a very nice block of code and saved my time&#8230;&#8230;&#8230;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Marcus B</title>
		<link>http://blog.sqlauthority.com/2007/02/01/sql-server-udf-function-to-convert-text-string-to-title-case-proper-case/#comment-59414</link>
		<dc:creator><![CDATA[Marcus B]]></dc:creator>
		<pubDate>Wed, 06 Jan 2010 21:44:41 +0000</pubDate>
		<guid isPermaLink="false">http://blog.sqlauthority.com/2007/02/01/function-to-convert-text-string-to-title-case/#comment-59414</guid>
		<description><![CDATA[Thank you so much!]]></description>
		<content:encoded><![CDATA[<p>Thank you so much!</p>
]]></content:encoded>
	</item>
</channel>
</rss>

