to update code in sql

Hi experts I need to update any string of a column with the following text = '%c/my/purchases.zx%'  to 'common/mybids.php'
Only 'c/my/purchases.zx' in the string should change to 'common/mybids.php', rest of the string should remain the same
Should I use replace function? please suggest
sqlcuriousAsked:
Who is Participating?
 
Jim HornMicrosoft SQL Server Developer, Architect, and AuthorCommented:
Not completely sure what you're asking here, but yes REPLACE() will replace a string with another...
Declare @value varchar(1000) = 'c/my/purchases.zxdjfkdsjfsl'
SELECT REPLACE(@value, 'c/my/purchases.zx', 'common/mybids.php') 

Open in new window

0
 
Tapan PattanaikSenior EngineerCommented:
Hi sqlcurious ,


update tbEmployee set EmpName=  REPLACE(EmpName, 'c/my/purchases.zx', 'common/mybids.php') from tbEmployee where EmpName like '%c/my/purchases.zx%';

Note:

1. Here tbEmployee  is  "Name of the table" and  EmpName is "name of the column."
2. If you are going to update the code in any live database, Please test the same in UAT server and make sure everything works fine.

Regards,
Tapan Pattanaik
0
 
sqlcuriousAuthor Commented:
thanks
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.