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
 General SQL Server Forums
 New to SQL Server Programming
 Proper Case Script in SQL

Author  Topic 

wazupjohn1
Starting Member

8 Posts

Posted - 2010-04-23 : 13:51:58
I would like to convert all the data in a column of a table in SQL to proper case. The table name is insurance and the column is city. So EL PASO will be El Paso. Need to keep all the spaces in between words. The don't want the entire table, just the column. Can someone help. I'm new at this.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-23 : 14:02:19
isnt this a presentation issue? why do u need to do this in table? you can always do this formatting while displaying by using a formatting function at front end

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

wazupjohn1
Starting Member

8 Posts

Posted - 2010-04-23 : 14:05:00
The column already has several thousand cities that I need to convert to proper case.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-04-23 : 14:05:58
quote:
Originally posted by wazupjohn1

The column already has several thousand cities that I need to convert to proper case.


but thats easily achievable during displaying at front end, no need to change table for that reason

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-23 : 14:09:11
For city names, I would actually recommend that the table be changed rather than doing it in the application. There's a proper spelling for cities, so it should be stored that way.

There are many functions out there that can do this, so do a search and see what works.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-23 : 14:11:02
After you fix the data, make sure to call the function any time an insert/update happens on that column so that manual clean-up isn't needed all of the time.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-23 : 14:12:07
Here's some links:
http://weblogs.sqlteam.com/jeffs/archive/2007/03/09/60131.aspx
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=47718

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

wazupjohn1
Starting Member

8 Posts

Posted - 2010-04-23 : 14:14:05
I don't know how to change tables though. And the information in already in upper case. It's not my database.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-23 : 14:16:30
Well you use an UPDATE statement to modify data in a table. Combine the UPDATE statement with a proper case function such as the one in Jeff's blog (in above link). Be sure to test it first by running SELECT statement combine with the proper case function.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

wazupjohn1
Starting Member

8 Posts

Posted - 2010-04-23 : 14:24:26
Can you give an example? I am really new at this?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-23 : 14:25:38
UPDATE SomeTable
SET SomeColumn = dbo.SomeFunction(SomeColumn)

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-23 : 14:26:18
For testing purpose:

SELECT TOP 100 dbo.SomeFunction(SomeColumn)
FROM SomeTable

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

wazupjohn1
Starting Member

8 Posts

Posted - 2010-04-23 : 14:49:30
LOL..I guess thats all im going to get huh?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-04-23 : 15:00:06
Well you have to figure out what proper case code/function to use. See the links for some examples. There are many other solutions out there.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tosscrosby
Aged Yak Warrior

676 Posts

Posted - 2010-04-23 : 15:02:14
Tara provided everything you need to complete your original request.

Terry

- Edit: Sorry Tara, sniped again!!

-- The problem with socialism is that you eventually run out of other people’s money. -- Margaret Thatcher
Go to Top of Page

wazupjohn1
Starting Member

8 Posts

Posted - 2010-04-23 : 15:08:59
She did if i knew what i was doing..thanks
Go to Top of Page
   

- Advertisement -