-
July 14th, 2005, 03:57 PM
#1
How to convert from UpperCase to TitleCase
I have user names stored in a table in capital letters (like JAMES BOND), and i want to convert them to title case (like James Bond)?
How will i do this, Any function you know, that could do the job?
Thanks.
-
July 15th, 2005, 03:04 AM
#2
Re: How to convert from UpperCase to TitleCase
Which database do you have?
Which language do you use?
With Access' SQL, data can be formatted with "Format", but it cannot do what you want. You have to write a little function to convert your strings after or before your query.
With Oracle's SQL, you have UPPER and LOWER, but that's not enough for your needs.
PHP has the built-in "ucwords" function which would be handy for you.
Code:
$bar = ucwords(strtolower($bar)); // HELLO WORLD! --> Hello World!
-
July 15th, 2005, 07:35 AM
#3
Re: How to convert from UpperCase to TitleCase
I am using SQL Server and want to do it using SQL.
-
July 16th, 2005, 03:35 AM
#4
Re: How to convert from UpperCase to TitleCase
With Access, you can do:
Code:
SELECT UCase$(Left$([Tb_users].[a_name],1)) & LCase$(Mid$([Tb_users].[a_name],2,InStr(2,[Tb_users].[a_name]," ") - 1))
& UCase$(mid$([Tb_users].[a_name],InStr(2,[Tb_users].[a_name]," ") + 1, 1))
& LCase$(right$([Tb_users].[a_name], Len([Tb_users].[a_name]) - InStr(2,[Tb_users].[a_name]," ") - 1)
) AS Expr1
FROM Tb_users;
-
July 29th, 2005, 10:12 AM
#5
Re: How to convert from UpperCase to TitleCase
For Oracle you can use Initcap
-
July 29th, 2005, 02:26 PM
#6
Re: How to convert from UpperCase to TitleCase
but i am using SQL Server. Any function avialable to do that in sql server?
-
August 3rd, 2005, 04:04 PM
#7
Re: How to convert from UpperCase to TitleCase
CREATE function INITCAP (@inString varchar(4000) )
/* INITCAP returns char, with the first letter of each word in uppercase, all other letters in lowercase. Words are delimited by white space or characters that are not alphanumeric */
returns varchar(4000)
as
BEGIN
DECLARE @i int, @c char(1),@result varchar(255)
SET @result=LOWER(@inString)
SET @i=2
SET @result=STUFF(@result,1,1,UPPER(SUBSTRING(@inString,1,1)))
WHILE @i<=LEN(@inString)
BEGIN
SET @c=SUBSTRING(@inString,@i,1)
IF (@c=' ') OR (@c=';') OR (@c=':') OR (@c='!') OR (@c='?') OR (@c=',')OR (@c='.')OR (@c='_')
IF @i<LEN(@inString)
BEGIN
SET @i=@i+1
SET @result=STUFF(@result,@i,1,UPPER(SUBSTRING(@inString,@i,1)))
END
SET @i=@i+1
END
RETURN @result
END
-
August 9th, 2005, 01:09 PM
#8
Re: How to convert from UpperCase to TitleCase
It worked.
Thank you so much.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|