user3742125
user3742125

Reputation: 627

replace sub string in SQL Server

I have a column in my table called "service". This has value like below.

0.0.0.1 /service/telco/fixedline/**intnet** 274511977 0

I need to replace this as below

0.0.0.1 /service/telco/fixedline/**_intnet** 274511977 0

If you notice this you could see that wherever the substring "intnet" is coming , all the occurances of it should be replaced with "_intnet".

Upvotes: 0

Views: 52

Answers (2)

Katusic
Katusic

Reputation: 84

select replace ('0.0.0.1 /service/telco/fixedline/intnet 274511977 0','intnet','_intnet')

Upvotes: 2

Yogesh Sharma
Yogesh Sharma

Reputation: 50173

I would do :

select stuff(col, charindex('intnet', col), 0, '_')

You can also use replace() :

select replace(col, 'intnet', '_intnet')

Upvotes: 2

Related Questions