Home Forums SQL Server 7,2000 T-SQL Change word that r in upper like the Excel function proper RE: Change word that r in upper like the Excel function proper

  • Or you can use this function, which I did post in the Scripts section, but since the website upgrade, for one reason or another it no longer comes up in a search.

     

    /*This function will evaluate an input string and convert it to title-case format.

    it uses the delimchars parameter to determine what are the triggering characters

     to indicate capitalization of the subsequent character*/

    CREATE FUNCTION  fnTitleCase (@instring nvarchar(256))

    RETURNS nvarchar(256)

    AS

    BEGIN

      DECLARE @strptr INT

      DECLARE @outstring nvarchar(255)

      DECLARE @strChar char(1)

      DECLARE @delimchars nvarchar(256)

      SET @outstring = ''

      SET @strptr = 0

      IF @delimchars is NULL

        /* Plug in typical upper-case delimiters

     NOTE: For localization purposes, you may wish to modify this */

        SET @delimchars = ' ''-_.,'

      /* Loop through the entire string */

      WHILE @strPtr < len(RTRIM(@instring))

        BEGIN

          SET @strptr = @strptr + 1

          SET @strchar = SUBSTRING(@instring,@strptr,1)

          IF @strptr = 1

     /* Assume that first character must always being upper-cased*/

            SET @outstring = UPPER(@strchar)

          ELSE

    /*Check for other upper-case trigger character */

            IF CHARINDEX(SUBSTRING(@instring,(@strptr - 1),1),@delimchars) > 0

    --          SET @outstring = SUBSTRING(@outstring,1,@strptr)+UPPER(@strchar)

              SET @outstring = @outstring+UPPER(@strchar)

            ELSE

              SET @outstring = @outstring+LOWER(@strchar)

        END

       RETURN @outstring

    END

     

    Cheers,

    Angela