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 2008 Forums
 Transact-SQL (2008)
 Creating a Script to add or remove spaces

Author  Topic 

jwarren
Starting Member

3 Posts

Posted - 2012-05-24 : 16:18:57
Does anyone know of a way to add or remove spaces after commas with a script? I have a SQL Database that is setup with this format: Lastname,Firstname and another Database that uses this format: Lastname, Firstname. I'd like to be able to add the space so they are uniform. Any thoughts?

Thanks!

Jonathan Warren

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-05-24 : 16:58:47
--remove the space
UPDATE t1
SET c5 = REPLACE(c5, ', ', ',')

--add the space
UPDATE t1
SET c5 = REPLACE(c5, ',', ', ')

You should really consider separating the data into two columns though. Putting them in one column is bad design.

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

Subscribe to my blog
Go to Top of Page
   

- Advertisement -