Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


ProperCase Function


ProperCase Function

Author
Message
mister.magoo
mister.magoo
SSCrazy
SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)SSCrazy (2.3K reputation)

Group: General Forum Members
Points: 2286 Visits: 7830
Jeff Moden (1/17/2014)
BWAAA-HAAA!!!! Dare I say IT? DARE I? Oh, what the heck...

"Ahhhhhhh MAGOO! You've done it again." :-P (Sorry ol' friend... I've been holding it back for more than a month and couldn't resist).


If I am honest, I kind of missed it Hehe

MM


select geometry::STGeomFromWKB(0x0106000000020000000103000000010000000B0000001000000000000840000000000000003DD8CCCCCCCCCC0840000000000000003DD8CCCCCCCCCC08408014AE47E17AFC3F040000000000104000CDCCCCCCCCEC3F9C999999999913408014AE47E17AFC3F9C99999999991340000000000000003D0000000000001440000000000000003D000000000000144000000000000000400400000000001040000000000000F03F100000000000084000000000000000401000000000000840000000000000003D0103000000010000000B000000000000000000143D000000000000003D009E99999999B93F000000000000003D009E99999999B93F8014AE47E17AFC3F400000000000F03F00CDCCCCCCCCEC3FA06666666666FE3F8014AE47E17AFC3FA06666666666FE3F000000000000003D1800000000000040000000000000003D18000000000000400000000000000040400000000000F03F000000000000F03F000000000000143D0000000000000040000000000000143D000000000000003D, 0);




  • Forum Etiquette: How to post Reporting Services problems
  • Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
  • How to Post Performance Problems - by Gail Shaw

  • dwain.c
    dwain.c
    SSCarpal Tunnel
    SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

    Group: General Forum Members
    Points: 4291 Visits: 6431
    I agree that you've done some very thorough testing here. Excellent work!

    Dohsan (1/17/2014)


    Dwain
    Ándre, Ándre, Luís And O'Brien Had A Low-Budget 3D Printer In Washington D.C.





    I wasn't sure how you wanted to handle "Low-Budget' and "3D" but either can be handled in the opposite manner by adjusting the match pattern.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
    Since random numbers are too important to be left to chance, let's generate some!
    Learn to understand recursive CTEs by example.
    Splitting strings based on patterns can be fast!
    My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables
    Luis Cazares
    Luis Cazares
    SSCrazy Eights
    SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)

    Group: General Forum Members
    Points: 8586 Visits: 18164
    dwain.c (1/17/2014)
    I agree that you've done some very thorough testing here. Excellent work!

    Dohsan (1/17/2014)


    Dwain
    Ándre, Ándre, Luís And O'Brien Had A Low-Budget 3D Printer In Washington D.C.





    I wasn't sure how you wanted to handle "Low-Budget' and "3D" but either can be handled in the opposite manner by adjusting the match pattern.


    Don't make me start with contractions or possessives. You'Ll Say It'S My Fault.Hehe


    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


    How to post data/code on a forum to get the best help: Option 1 / Option 2
    Dohsan
    Dohsan
    Mr or Mrs. 500
    Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)Mr or Mrs. 500 (516 reputation)

    Group: General Forum Members
    Points: 516 Visits: 3384
    Luis Cazares (1/17/2014)
    dwain.c (1/17/2014)
    I agree that you've done some very thorough testing here. Excellent work!

    Dohsan (1/17/2014)


    Dwain
    Ándre, Ándre, Luís And O'Brien Had A Low-Budget 3D Printer In Washington D.C.





    I wasn't sure how you wanted to handle "Low-Budget' and "3D" but either can be handled in the opposite manner by adjusting the match pattern.


    Don't make me start with contractions or possessives. You'Ll Say It'S My Fault.Hehe


    hah very true!
    ChrisM@home
    ChrisM@home
    Ten Centuries
    Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

    Group: General Forum Members
    Points: 1163 Visits: 9738
    This thread has been fun to watch, thanks folks! Here's an option I'm surprised nobody posted up:
    CREATE FUNCTION [dbo].[IF_ProperWithREPLACE]
    (
    @inputstring VARCHAR(8000)
    )
    RETURNS TABLE WITH SCHEMABINDING
    AS
    RETURN
    (
    SELECT ProperisedString =
    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(
    ' '+@inputstring COLLATE Latin1_General_BIN,
    ' a',' A'), ' b',' B'), ' c',' C'), ' d',' D'), ' e',' E'), ' f',' F'), ' g',' G'), ' h',' H'), ' i',' I'),
    ' j',' J'), ' k',' K'), ' l',' L'), ' m',' M'), ' n',' N'), ' o',' O'), ' p',' P'), ' q',' Q'), ' r',' R'),
    ' s',' S'), ' t',' T'), ' u',' U'), ' v',' V'), ' w',' W'), ' x',' X'), ' y',' Y'), ' z',' Z')
    )



    It's about 8x faster than any of the solutions posted so far, leaving some scope for dealing with weird stuff like accents.


    Low-hanging fruit picker and defender of the moggies





    For better assistance in answering your questions, please read this.




    Understanding and using APPLY, (I) and (II) Paul White

    Hidden RBAR: Triangular Joins / The "Numbers" or "Tally" Table: What it is and how it replaces a loop Jeff Moden
    Sean Lange
    Sean Lange
    SSCoach
    SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

    Group: General Forum Members
    Points: 16673 Visits: 17032
    I came back to this thread today because I was trying to proper case some stuff around here. I needed to exclude tokens that contain at least a single digit but all other tokens should be init caps.

    I made a slight modification to Dwain's that worked well for my purposes.


    CREATE FUNCTION [dbo].[ProperCaseWithNumbers]
    (
    @StrIn VARCHAR(255)
    )
    RETURNS TABLE WITH SCHEMABINDING
    AS
    RETURN

    SELECT STUFF((
    SELECT CASE
    WHEN split.Item LIKE '%[0-9]%'
    THEN ' ' + split.Item
    ELSE ' ' + Upper(LEFT(split.Item, 1)) + Lower(Substring(split.Item, 2, 255))
    END AS word
    FROM dbo.Delimitedsplit8k(@StrIn, ' ') split
    FOR XML PATH('')
    ,TYPE
    ).value('.', 'varchar(255)'), 1, 1, '') AS ProperCased



    We have some data coming from the mainframe and it is all caps but I need to make this data more "user friendly". Here is an example of this one in action.


    declare @MyVals table (SeriesName varchar(25))
    insert @MyVals
    select '9400 SERIES' union all
    select '9760 SERIES' union all
    select 'ADE360 SERIES' union all
    select 'CUSTOM' union all
    select 'M16360 SERIES' union all
    select 'N1260 SERIES' union all
    select 'N3160 SERIES' union all
    select 'PA360 SERIES' union all
    select 'S260 SERIES'

    select *
    from @MyVals v
    cross apply dbo.ProperCaseWithNumbers(v.SeriesName)



    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Moden's splitter.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
    Understanding and Using APPLY (Part 1)
    Understanding and Using APPLY (Part 2)
    dwain.c
    dwain.c
    SSCarpal Tunnel
    SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)SSCarpal Tunnel (4.3K reputation)

    Group: General Forum Members
    Points: 4291 Visits: 6431
    Sean Lange (2/26/2014)


    I made a slight modification to Dwain's that worked well for my purposes.



    Can't say I see that much of a resemblance but it is always good to hear success stories.


    My mantra: No loops! No CURSORs! No RBAR! Hoo-uh!

    My thought question: Have you ever been told that your query runs too fast?

    My advice:
    INDEXing a poor-performing query is like putting sugar on cat food. Yeah, it probably tastes better but are you sure you want to eat it?
    The path of least resistance can be a slippery slope. Take care that fixing your fixes of fixes doesn't snowball and end up costing you more than fixing the root cause would have in the first place.


    Need to UNPIVOT? Why not CROSS APPLY VALUES instead?
    Since random numbers are too important to be left to chance, let's generate some!
    Learn to understand recursive CTEs by example.
    Splitting strings based on patterns can be fast!
    My temporal SQL musings: Calendar Tables, an Easter SQL, Time Slots and Self-maintaining, Contiguous Effective Dates in Temporal Tables
    Sean Lange
    Sean Lange
    SSCoach
    SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)SSCoach (16K reputation)

    Group: General Forum Members
    Points: 16673 Visits: 17032
    dwain.c (2/26/2014)
    Sean Lange (2/26/2014)


    I made a slight modification to Dwain's that worked well for my purposes.



    Can't say I see that much of a resemblance but it is always good to hear success stories.


    Doh!!! That's because it was a modification of the code Luis posted.

    Thanks Luis!!!

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Moden's splitter.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
    Understanding and Using APPLY (Part 1)
    Understanding and Using APPLY (Part 2)
    Luis Cazares
    Luis Cazares
    SSCrazy Eights
    SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)SSCrazy Eights (8.6K reputation)

    Group: General Forum Members
    Points: 8586 Visits: 18164
    Sean Lange (2/27/2014)
    dwain.c (2/26/2014)
    Sean Lange (2/26/2014)


    I made a slight modification to Dwain's that worked well for my purposes.



    Can't say I see that much of a resemblance but it is always good to hear success stories.


    Doh!!! That's because it was a modification of the code Luis posted.

    Thanks Luis!!!


    I knew the code look familiar :-D
    I guess that's the benefit of collective intelligence.


    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?


    How to post data/code on a forum to get the best help: Option 1 / Option 2
    batesview
    batesview
    SSC Rookie
    SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)SSC Rookie (34 reputation)

    Group: General Forum Members
    Points: 34 Visits: 422
    I wonder if a CLR function would be worth considering here? .NET includes the System.Globalization.TextInfo.ToTitleCase() function which seems to do a pretty good job getting things properly capitalized. Not perfect but perhaps an extension method could handle the edge cases ?
    Go


    Permissions

    You can't post new topics.
    You can't post topic replies.
    You can't post new polls.
    You can't post replies to polls.
    You can't edit your own topics.
    You can't delete your own topics.
    You can't edit other topics.
    You can't delete other topics.
    You can't edit your own posts.
    You can't edit other posts.
    You can't delete your own posts.
    You can't delete other posts.
    You can't post events.
    You can't edit your own events.
    You can't edit other events.
    You can't delete your own events.
    You can't delete other events.
    You can't send private messages.
    You can't send emails.
    You can read topics.
    You can't vote in polls.
    You can't upload attachments.
    You can download attachments.
    You can't post HTML code.
    You can't edit HTML code.
    You can't post IFCode.
    You can't post JavaScript.
    You can post emoticons.
    You can't post or upload images.

    Select a forum

































































































































































    SQLServerCentral


    Search