0

Hey Friends I want to replace 1 to 'asd' and 10 to 'asdddd' in a string like 1and2and10 but it replace it to 'asd'and2and'asd'0 in sql server please help.

Thank you

2
  • share whatever you have tried yet. some query or anything other. Commented Aug 2, 2018 at 6:22
  • Please add some sample data and also anything you have tried. Commented Aug 2, 2018 at 6:25

1 Answer 1

1

Try:

SELECT REPLACE(REPLACE('1and2and10' , '10', 'asdddd'), '1', 'asd')

or with table:

SELECT REPLACE(REPLACE(myColumn , '10', 'asdddd'), '1', 'asd') FROM myTable
Sign up to request clarification or add additional context in comments.

3 Comments

I am not sure if this will be the string every time and number can go up to 100 in this case so I can not take risk of hard codes
@Soul_Hunter Then update the question and include all cases. What you saying now wasn't mentioned in question.
I am saying that there can be a case when (1and2and3and4)or(3and29and1)

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.