Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to replace a string with another string in a c

Author  Topic 

madhu.paddu
Starting Member

6 Posts

Posted - 2007-12-12 : 08:56:59
hi friends

can any one help me how to replace a string with another string in a column of table with out effecting the other charcaters

ex:

In srinivas reddy only 'srinivas' has to replace with 'sreenivas'

regards



nukala

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-12-12 : 08:59:59
select replace('srinivas reddy', 'srinivas' ,'sreenivas')


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhu.paddu
Starting Member

6 Posts

Posted - 2007-12-12 : 09:09:15
hi friend
can u plzexplain in detail

ex;

srinivas
srinivas reddy
srinivasulu
srinivasgoud

in all this strings
i want to replace the srinivas by sreenivas.

can give me full syntax for this one.

thanks in advance
regards
madhu

nukala
Go to Top of Page

RickD
Slow But Sure Yak Herding Master

3608 Posts

Posted - 2007-12-12 : 09:11:33
You have already been given the syntax. Look up REPLACE in Books Online.
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-12-12 : 09:13:46
from BOL http://msdn2.microsoft.com/en-us/library/ms186862.aspx


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-12 : 09:17:45
You need to apply that in the column

select replace(your_column, 'srinivas' ,'sreenivas') from table


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhu.paddu
Starting Member

6 Posts

Posted - 2007-12-12 : 09:27:16
hi friends

if am using

select replace('srinivas reddy','srinivas','sreenivas');

it replaceings all the strings with srinivas reddy in that cloumn.

i have table consists of emp no ,ename,job columns.

ename(column)

srinivas
srinivas reddy
madhu
sudhan
srinivasulu
srinivasgoud

in ename column i have to replace the srinivas by sreenivas.

for this i had used this syntax

select replace('srinivas%','srinivas','sreenivas') from xxxx;

it giving result is

srinivas%
srinivas%
srinivas%
srinivas%
srinivas%
srinivas%
srinivas%

what can i do.

regards
madhu

nukala
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-12 : 09:28:34
quote:
Originally posted by madhu.paddu

hi friends

if am using

select replace('srinivas reddy','srinivas','sreenivas');

it replaceings all the strings with srinivas reddy in that cloumn.

i have table consists of emp no ,ename,job columns.

ename(column)

srinivas
srinivas reddy
madhu
sudhan
srinivasulu
srinivasgoud

in ename column i have to replace the srinivas by sreenivas.

for this i had used this syntax

select replace('srinivas%','srinivas','sreenivas') from xxxx;

it giving result is

srinivas%
srinivas%
srinivas%
srinivas%
srinivas%
srinivas%
srinivas%

what can i do.

regards
madhu

nukala


Did you read my previous reply?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhu.paddu
Starting Member

6 Posts

Posted - 2007-12-12 : 09:32:03
hi friends

thank you very much friends for clarifying my doubt.

i got the solution
regrads
madhu

nukala
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-12 : 09:35:00
Always make sure you read the replies properly before asking additional questions

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -