?
Solved

how can i rename a picture name stored in a table

Posted on 2013-06-28
4
Medium Priority
?
271 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Suggested Courses

800 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