Solved

how can i rename a picture name stored in a table

Posted on 2013-06-28
4
270 Views
Last Modified: 2013-06-28
Hi

I have a database with a table named myimages, this contains a field named imagepath which is an ntext datatype.

Imagepath contains the names of several thousand images a lot of which end in .tif

I want to rename the .tif files to be .png

How can I do this?

when I tried

SELECT
 replace([imagePath],".tif",".png")
     
  FROM [mydatabase].[dbo].[myImages]
  where imagepath like '%.tif'

I received an error message.

Can anyone help me with the syntax to update the table?
0
Comment
Question by:Nemetona
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 27

Accepted Solution

by:
Zberteoc earned 500 total points
ID: 39284926
update [mydatabase].[dbo].[myImages] set
	[imagePath]=replace([imagePath],".tif",".png")
where
	[imagePath] like '%.tif'

Open in new window

0
 
LVL 60

Expert Comment

by:Kevin Cross
ID: 39284929
The error probably stems from the double quotes. SQL Server uses single quotes.
If that is just a type-o in the question here, please post the error you are receiving.

As an aside, if there is a possibility that someone named a file with '.tif' in the name, you may want to consider taking the first part of the string minus the last four characters, then just add '.png' to the end.
0
 
LVL 27

Expert Comment

by:Zberteoc
ID: 39284934
Yes, I missed to change the " to '.  Actually I was editing my first post but I could'n save it due to already posted message above. So the update should be:

update [mydatabase].[dbo].[myImages] set
	[imagePath]=replace([imagePath],'.tif','.png')
where
	[imagePath] like '%.tif'

Open in new window

0
 

Author Closing Comment

by:Nemetona
ID: 39285128
Thank you
0

Featured Post

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Viewers will learn how the fundamental information of how to create a table.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

729 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question