Solved

Replace one char in a string

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

863 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

19 Experts available now in Live!

Get 1:1 Help Now