Question : Title Case SQL Statement

Is there a SQL statement to convert upper case characters to title case?

I can do it in a VB program if I need to write one, but thought it may be easier just to run a SQL statement. I just can't find any references as to whether there is support for it in T-SQL.

Thanks,

JB

Answer : Title Case SQL Statement

Try this:

CREATE FUNCTION InitCap (@pInputString varchar(4000) )
RETURNS VARCHAR(4000)
AS
BEGIN
DECLARE @vIndex          INT
DECLARE @vChar           CHAR(1)
DECLARE @vOutputString   VARCHAR(255)
SET @vOutputString = LOWER(@pInputString)
SET @vIndex = 2
SET @vOutputString = STUFF(@vOutputString, 1, 1, UPPER(SUBSTRING(@pInputString,1,1)))
WHILE @vIndex <= LEN(@pInputString)
BEGIN
    SET @vChar = SUBSTRING(@pInputString, @vIndex, 1)
    IF @vChar IN (' ', ';', ':', '!', '?', ',', '.', '_', '-', '/', '&', '''', '(')
        IF @vIndex + 1 <= LEN(@pInputString)
        BEGIN
            IF @vChar != '''' OR
               UPPER(SUBSTRING(@pInputString, @vIndex + 1, 1)) != 'S'
                SET @vOutputString=STUFF(@vOutputString, @vIndex + 1, 1, UPPER(SUBSTRING(@pInputString, @vIndex + 1, 1)))
        END
    SET @vIndex = @vIndex + 1
END
RETURN @vOutputString
END

Random Solutions  
 
programming4us programming4us