Click here to Skip to main content
15,898,869 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all ,
i have a question , ihave a String which is
SQL
' the quick brown fox jumps over the lazy dog'


and in my Stored Procedure i want to create an Output like this

SQL
' The Quick Brown Fox Jumps Over The Lazy Dog'


ones my Script see a ' ' (Space) i will convert the first letter to Upper case.

Thanks all.
Posted
Comments
Arunprasath Natarajan 26-Oct-12 23:37pm    
what you have tried out, put your code

First Create a Function as below and use the same.
It takes the input value in a string and it finds the white space and make the next text to white space as Upper case.
SQL
CREATE FUNCTION FN_TITLECASE (@INPUTSTR VARCHAR(250))
RETURNS VARCHAR(250)
AS BEGIN
DECLARE @TEMPSTR VARCHAR(250)
DECLARE @I INT
SET @TEMPSTR = LOWER(@INPUTSTR)

SET @TEMPSTR = UPPER(LEFT(@TEMPSTR,1)) + SUBSTRING(@TEMPSTR,2,LEN(@TEMPSTR))

WHILE CHARINDEX(' ',@TEMPSTR,1) > 0
 BEGIN
  SET @I = CHARINDEX(' ',@TEMPSTR,1)
  SET @TEMPSTR = LEFT(@TEMPSTR,@I-1) + '~*' + UPPER(SUBSTRING(@TEMPSTR,@I + 1,1)) +SUBSTRING(@TEMPSTR,@I+2,LEN(@TEMPSTR))
 END


 SET @TEMPSTR = REPLACE(@TEMPSTR,'~*',' ')
 SET @INPUTSTR = @TEMPSTR
 RETURN @INPUTSTR
END


SELECT DBO.FN_TITLECASE('I GOT YOUR REQUIREMENT KINDLY MAKE A NOTE')
 
Share this answer
 
Hello,
I have tried this Stored Procedure , you can refer this:

SQL
Create procedure dbo.titleupcase @str varchar(30)
as
begin

    Declare @i int, @len int, @newstr varchar(30),@new varchar(30),@space int

    set @i=1
    set @newstr=''
    set @space=1

    select @len=len(@str)

    while (@i<=@len )
    begin
        if (@space=1)
        begin
            Select @new= upper(substring(@str,@i,1))
            set @space=0
        end
        else
        begin
            Select @new= substring(@str,@i,1)
        end

            if (@new='')
            begin
                set @space=1
            end
        set @newstr=@newstr+@new        
        set @i=@i+1
    end
select @newstr
end
 
Share this answer
 
v3
Comments
Arunprasath Natarajan 27-Oct-12 0:40am    
Good work princess

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900