0

I have a SQL Server table with the following column names:

  • ItemID
  • Title
  • Description
  • ImagePath

filled with about 300 items. Now, the ImagePath column name is filled with different images for each entry, but they all have the same root folder in common (e.g. /project/images/1.jpg, /project/images/2.jpg, /project/images/3.jpg, etc.). I have been asked to move the images somewhere else, however, so now the root folder has changed (suppose the new location is /projects/project-a/images), and I'd like to know if there's a way of updating the ImagePath at once for all entries, as opposed to having to go through every single one of them manually. If possible, I'd like to avoid dropping and creating the table again.

1
  • 1
    Am I missing something; what's wrong with a simple update script? Commented Jan 17, 2016 at 10:20

1 Answer 1

4

If the data type of the ImagePath column is char, varchar, nchar, or nvarchar, but NOT text or ntext, you can simply use the built in REPLACE method:

UPDATE tableName
SET ImagePath = REPLACE(ImagePath, '/project/images/', '/projects/project-a/images')
Sign up to request clarification or add additional context in comments.

1 Comment

This is exactly what I need! Thank you!

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.