Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Replace one char in a string

Posted on 2004-08-31
3
Medium Priority
?
226 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 2000 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
I have a large data set and a SSIS package. How can I load this file in multi threading?
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

688 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