I need letters added to contents of a field in a database if other letters are present.

My table name is "webstockforuploadrob" and the field name is "thumb nail image name". An example of one of the field contents is XX152TH.jpg. I need a query that adds P1 before the TH.jpg if TH.jpg is present. The result should read XX152P1TH.jpg Hope someone can help
oldmillsaddleryAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

DimitrisSenior Solution ArchitectCommented:
This works.

UPDATE TableName
SET Image_name = REPLACE(image_name,'TH.jpg','P1TH.jpg')
Where RIGHT(Image_name,3)='TH.jpg'

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DimitrisSenior Solution ArchitectCommented:
Sorry the where is like thsi
WHERE RIGHT(image_name,5)='TH.jpg' :)
0
oldmillsaddleryAuthor Commented:
thanks for this but I am not getting it totally correct. I have a table called newwebstock and one of the fields is called Thumbnail Image name

 UPDATE NEWWEBSTOCK SET Thumbnail_Image_name = REPLACE(Thumbnail_Image_name,'TH.jpg','P1TH.jpg')
WHERE RIGHT(Thumbnail_Image_name,5)='TH.jpg';


when I run the query it asks me to enter parameter value for  Thumbnail_Image_name

Sorry it is something stupid I am doing I guess
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

Arthur_WoodCommented:
are you sure that the field is named "Thumbnail_Image_name"
Also, this query will lead to significant problems if it is inadvertantly executed successfully more that once.  After the first succesful execution, the field Thumbnail_Image_name will still end with the final 5 characters as specified in the where clause, and thus a second application of the query will again find all the same records, and will modify the end of the field in the same way, so that the field will then read (for example):
XX152P1P1TH.jpg  
 Initially                      After First Eexcution               After Second Execution
XX152TH.jpg            XX152P1TH.jpg                     XX152P1P1TH.jpg
0
Arthur_WoodCommented:
in the original question, you state
the field name is "thumb nail image name".  
in the query you posted, you have the name as  
 Thumbnail_Image_name
which is it, as it cannot be both.  The fact that you are getting a prompt for that 'parameter' name (Thumbnail_Image_name) suggests that the field is actually named  
thumb nail image name
0
awking00Information Technology SpecialistCommented:
Can you post a describe for newwebstock so we can see actual field name? Also, you can eliminate additional executions by adding -
and RIGHT(Thumbnail_Image_name,7) <>'P1TH.jpg';
0
oldmillsaddleryAuthor Commented:
Thanks all I seem to have got things sorted with the file name
0
Arthur_WoodCommented:
Glad to be of assistance.  Just need to be sure that once this query has been executed, that it is not executed again, as I noted, above.
 
AW
0
awking00Information Technology SpecialistCommented:
By the way, it should be
where right(<fieldname>,6) = 'TH.jpg'
and right(<fieldname>,8) <> 'P1TH.jpg'
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Query Syntax

From novice to tech pro — start learning today.