Solved

Replace one char in a string

Posted on 2004-08-31
3
220 Views
Last Modified: 2006-11-17
I need to replace the : in 'My Files: username' with a - to make it 'My Files- Username'.

The column name is [name] and I have to do this for all the rows in the table where [name] like 'My Files:%'.

How can I do this? (I know I will use a cursor to extract all rows and some form of substring and charindex.)

I need a quick answer to be honest.
Thanks.

0
Comment
Question by:danielvic
  • 2
3 Comments
 
LVL 3

Expert Comment

by:Minna
ID: 11948987
Update <table>
set [name] = replace([name], ':', '-')
0
 
LVL 3

Accepted Solution

by:
Minna earned 500 total points
ID: 11949018
Oh I forgot to mention, that query will update all your rows without the need for cursors.
And add your where clause for better performance

Update <table>
set [name] = replace([name], ':', '-')
where [name] like 'My Files:%'
0
 

Author Comment

by:danielvic
ID: 11949060
well, that was easy! didn't know about the replace function.
I did a search for replace substring before posting this question and didn't find any hits with replace function in the answer (?!).
Thanks for the quick reply. It works (of course).
0

Featured Post

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
I have a large data set and a SSIS package. How can I load this file in multi threading?
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question