0

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".

1
  • 2
    What have you tried? Have you searched for "replace string SQL Server", or similar, on your preferred search engine? (hint: REPLACE (Transact-SQL)) Commented Oct 24, 2018 at 10:24

2 Answers 2

2

I would do :

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

You can also use replace() :

select replace(col, 'intnet', '_intnet')
Sign up to request clarification or add additional context in comments.

1 Comment

Prefer this answer as it uses the column name rather than the literal string. I think it's safe to assume the value of each row will be different, rather than the exact same string over and over.
2
select replace ('0.0.0.1 /service/telco/fixedline/intnet 274511977 0','intnet','_intnet')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.