Stored Procedure Replace function

If I have a simple select statement like this:
Select Name from tblNames where ID = 1
I want to replace any occurances in Name with the following:
Replace & with &
Replace " with "
Replace - with –
Is there an easy way to do this in a stored procedure?
LATurkAsked:
Who is Participating?
 
RiteshShahConnect With a Mentor Commented:
it will work for sure, see my last post. i did it practically and it worked
0
 
RiteshShahCommented:
select replace(name,'&','&')
0
 
RiteshShahCommented:
you can do like this

create proc replaceReturn
as
Select replace(Name,'&','&') as name from emps
0
What Kind of Coding Program is Right for You?

There are many ways to learn to code these days. From coding bootcamps like Flatiron School to online courses to totally free beginner resources. The best way to learn to code depends on many factors, but the most important one is you. See what course is best for you.

 
RiteshShahCommented:
refined version for you.



create proc replaceReturn
as
Select replace(replace(replace(Name,'&','&'),'"','"'),'-','&ndash') as name from tblNames where id=1

Open in new window

0
 
LATurkAuthor Commented:
But what if one name had all three in it.  
For Example: John "the man" & Smith-Jones
I know that's ridiculous but I want to be sure none of the characters are in this field.
0
 
RiteshShahCommented:
see this is what you want, right?

Select replace(replace(replace('John "the man" & Smith-Jones','&','&'),'"','"'),'-','&ndash')

will be looked like

John "the man" & Smith&ndashJones
0
 
LATurkAuthor Commented:
Thanks!  Works perfectly!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.