Results 1 to 4 of 4
  1. #1
    Join Date
    Mar 2004
    Posts
    20

    Question Unanswered: Proper Names function

    Hello: a nice simple question (I hope). Is there a MS SQL equivilant to PROPER (string) which would return "Fred Bloggs" from "FRED BLOGGS" and equally from "FrEd bLoggs" ? I cant find such ....


    Gerry

  2. #2
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    No one?

    Code:
    
    
    DECLARE @x varchar(8000)
    SELECT @x = 'FRED BLOGGS'
    
    SELECT    UPPER(SUBSTRING(@x,1,1))
    	+ LOWER(SUBSTRING(@x,2,CHARINDEX(' ',@x)-1))
    	+ UPPER(SUBSTRING(@x,CHARINDEX(' ',@x)+1,1))
    	+ LOWER(SUBSTRING(@x,CHARINDEX(' ',@x)+2,LEN(@x)-CHARINDEX(' ',@x)+2))
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

  3. #3
    Join Date
    Mar 2004
    Posts
    20

    Unhappy

    Thanks. I was hoping for a nice simple built in function but hey-ho

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    OK

    Code:
    CREATE FUNCTION udf_ProperName(@x varchar(8000))
    RETURNS varchar(8000)
    AS
      BEGIN  
    	RETURN    UPPER(SUBSTRING(@x,1,1))
    		+ LOWER(SUBSTRING(@x,2,CHARINDEX(' ',@x)-1))
    		+ UPPER(SUBSTRING(@x,CHARINDEX(' ',@x)+1,1))
    		+ LOWER(SUBSTRING(@x,CHARINDEX(' ',@x)+2,LEN(@x)-CHARINDEX(' ',@x)+2))
      END
    GO
    
    SELECT dbo.udf_ProperName('FRED BLOGGS')
    GO
    
    DROP Function udf_ProperName
    GO
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •