SVI
SVI

Reputation: 1651

Update column to insert spaces in one of the columns in sql server table

How do I achieve the following by a stored procedure or sql script in sql server?

Say for example, I have a-b in one of the columns and I need to update that column to a - b instead. How do I insert spaces before and after the dash in existing data in my database.

Upvotes: 0

Views: 2876

Answers (2)

amit_g
amit_g

Reputation: 31250

update TableName set ColumnName = Replace(ColumnName, '-', ' - ') where SomeCondition ...

Upvotes: 0

Joe Stefanelli
Joe Stefanelli

Reputation: 135799

UPDATE YourTable
    SET YourColumn = REPLACE(YourColumn, '-', ' - ')

Upvotes: 1

Related Questions