Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Change String to Title Case(Initcap) Expand / Collapse
Author
Message
Posted Monday, October 25, 2010 10:08 PM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, September 5, 2014 6:19 AM
Points: 12, Visits: 105
Comments posted to this topic are about the item Change String to Title Case(Initcap)
Post #1010516
Posted Tuesday, October 26, 2010 1:13 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, January 10, 2014 1:01 PM
Points: 3, Visits: 35
This is a very simplistic implementation of a function that would be very useful if fully implemented. Unfortunately it doesn't take into account the myriad of language-specific exceptions to title case. In English, typically you don't "upper case" the first letter of words like "of" and "and". You don't lower case the 2nd/3rd letters of some Celtic surnames (eg. McCall or O'Toole). Sometimes you don't lowercase the first letter after a hyphen (eg. Guinea-Bissau). I'm sure there's more, it's a bit mind-blowing when you get into it!

James McCall
Post #1011102
Posted Thursday, October 28, 2010 8:34 PM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Wednesday, September 17, 2014 10:31 AM
Points: 5, Visits: 284
Thanks for the useful script!

However, I noticed that you used:

Select @vString = Replace(@vString, @vWord, '')

This replaces _all_ occurrences of @vWord in @vString, eliminating repeated words in the title.

I fixed this using:

Select @vString = RIGHT(@vString, LEN(@vString) - LEN(@vWord))

This will just strip the first word from the string, which I believe was the intended behaviour.

Cheers,
David Scheppers.
Post #1012785
Posted Wednesday, November 3, 2010 8:41 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, August 26, 2014 10:50 AM
Points: 13, Visits: 237
Like any TSQL function that iterates through strings, this will run fine on small sets or a single field, but if you're going to use this in large set queries, you might want to consider writing it as a CLR assembly: C# or VB.Net are faster at string parsing.
Post #1015274
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse