Solved

Replace one char in a string

Posted on 2004-08-31
3
218 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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

706 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now