Explore Courses Blog Tutorials Interview Questions
0 votes
1 view
in SQL by (20.3k points)

I've got a table with two columns, ID and Value. I want to change a part of some strings in the second column.

Example of Table:

ID            Value


1             c:\temp\123\abc\111

2             c:\temp\123\abc\222

3             c:\temp\123\abc\333

4             c:\temp\123\abc\444

Now the 123\ in the Value string is not needed. I tried UPDATE and REPLACE:


SET Value = REPLACE(Value, '%123%', '')


When I execute the script SQL Server does not report an error, but it does not update anything either. Why is that?

1 Answer

0 votes
by (40.4k points)

Avoid using the wildcards in the REPLACE – As it only finds the string you enter for the second argument.

 So, use the below code:


SET Value = REPLACE(value, '231\', '')


(You need to add the \ in the replace as I assume you don't need to do that either)

Related questions

0 votes
1 answer
0 votes
1 answer
+1 vote
1 answer
0 votes
1 answer

Browse Categories