Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Capitalize First Letter

Author  Topic 

thehandsomecode
Yak Posting Veteran

51 Posts

Posted - 2008-06-06 : 15:47:49
I have a table name filteredcontact and a column named first name.
how do i change the column first name to capitalize the first letter and leave the remaining characters as is.

Compnetsyslc

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2008-06-06 : 16:01:37
Use the sp_rename stored procedure.

You can lookup the exact usage in SQL Server Books Online.



CODO ERGO SUM
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-06-07 : 04:26:01
quote:
Originally posted by thehandsomecode

I have a table name filteredcontact and a column named first name.
how do i change the column first name to capitalize the first letter and leave the remaining characters as is.

Compnetsyslc


Are you asking for renaming column itself or capitalise the data inside column? If its data you've to change,then use this

SELECT UPPER(LEFT(firstname,1))+SUBSTRING(firstname,2,LEN(firstname)) FROM filteredcontact


If you just wanted to change it only for displaying and do not need the actual data in table to change and

UPDATE filteredcontact
SET firstname=UPPER(LEFT(firstname,1))+SUBSTRING(firstname,2,LEN(firstname))


If you want change to be made to actual data itself
Go to Top of Page

blindman
Master Smack Fu Yak Hacker

2365 Posts

Posted - 2008-06-07 : 11:06:05
quote:
Originally posted by Michael Valentine Jones

Use the sp_rename stored procedure.

You can lookup the exact usage in SQL Server Books Online.



CODO ERGO SUM

Go get another cup of coffee, Michael... ;)

e4 d5 xd5 Nf6
Go to Top of Page

thehandsomecode
Yak Posting Veteran

51 Posts

Posted - 2008-06-07 : 16:26:23
quote:
Originally posted by visakh16

quote:
Originally posted by thehandsomecode

I have a table name filteredcontact and a column named first name.
how do i change the column first name to capitalize the first letter and leave the remaining characters as is.

Compnetsyslc


Are you asking for renaming column itself or capitalise the data inside column? If its data you've to change,then use this

SELECT UPPER(LEFT(firstname,1))+SUBSTRING(firstname,2,LEN(firstname)) FROM filteredcontact


If you just wanted to change it only for displaying and do not need the actual data in table to change and

UPDATE filteredcontact
SET firstname=UPPER(LEFT(firstname,1))+SUBSTRING(firstname,2,LEN(firstname))


If you want change to be made to actual data itself





Thank you this worked fine. I needed to change the data itself. we do mass imports at times and the first names and last names arent always what i like to call neat. Thank you

Compnetsyslc
Go to Top of Page

fguiccia
Starting Member

3 Posts

Posted - 2011-05-10 : 10:26:27
Thanks, very handy :)

Ferruccio Guicciardi
BI Consultant
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-05-10 : 10:35:22
declare @str varchar(10)
set @str = 'adshiou'
select STUFF(@str,1,1,UPPER(left(@str,1)) )

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-05-11 : 06:55:14
For multiple words, use
http://beyondrelational.com/blogs/madhivanan/archive/2010/07/19/initcap-function.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

briburrell
Starting Member

1 Post

Posted - 2012-10-14 : 12:15:30

In mysql the update statement is;
update User set firstname = CONCAT( UPPER( LEFT( firstname, 1 ) ) , SUBSTRING( firstname, 2 ) )

quote:
Originally posted by visakh16

quote:
Originally posted by thehandsomecode

I have a table name filteredcontact and a column named first name.
how do i change the column first name to capitalize the first letter and leave the remaining characters as is.

Compnetsyslc


Are you asking for renaming column itself or capitalise the data inside column? If its data you've to change,then use this

SELECT UPPER(LEFT(firstname,1))+SUBSTRING(firstname,2,LEN(firstname)) FROM filteredcontact


If you just wanted to change it only for displaying and do not need the actual data in table to change and

UPDATE filteredcontact
SET firstname=UPPER(LEFT(firstname,1))+SUBSTRING(firstname,2,LEN(firstname))


If you want change to be made to actual data itself




-bb..
Go to Top of Page
   

- Advertisement -