Solved

delete string from field

Posted on 2014-01-15
6
354 Views
Last Modified: 2014-01-16
Access 2010:

I have  table:
table_images
2 fields:
Primary_ number
Primary_Image

What I need:

In the field "Primary_Image"

If any of the data has a name with a  "_ "<UNDERSCORE>  in it ... like below

3NU39_AW99.JPG

I need it to be changed to

3NU39.JPG

so starting at the  "_ "<UNDERSCORE>   delete the string behind it. but keep the  .jpg

example: again
primary_image
3NU24_AW99.JPG
3NU22_AW99.JPG
24Z173_AS01.JPG
3NU21_AW99.JPG

will be:
primary_image
3NU24.JPG
3NU22.JPG
24Z173.JPG
3NU21.JPG


Thanks
fordraiders
0
Comment
Question by:fordraiders
[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
  • 3
  • 2
6 Comments
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39783023
After backing up your table, try something like

UPDATE yourTable
SET Primary_Image = Left([Primary_Image], instr([Primary_Image], "_")-1 & Mid([Primary_Image], instrrev([Primary_Image]), "."))
WHERE instr([Primary_Image], "_") > 0

You might want to start out with:

SELECT [Primary_Image], Left([Primary_Image], instr([Primary_Image], "_")-1 & Mid([Primary_Image], instrrev([Primary_Image]), ".")) as ModPrimImage
WHERE instr([Primary_Image], "_") > 0
0
 
LVL 3

Author Comment

by:fordraiders
ID: 39783145
get a wrong number of arguments error..
0
 
LVL 47

Accepted Solution

by:
Dale Fye (Access MVP) earned 500 total points
ID: 39783245
a couple of parenthesis issues.  For the SELECT statement try:

SELECT [Primary_Image], Left([Primary_Image], instr([Primary_Image], "_")-1) & Mid([Primary_Image], instrrev([Primary_Image], ".")) as ModPrimImage
WHERE instr([Primary_Image], "_") > 0

for the UPdate it would look like:

UPDATE yourTable
SET Primary_Image = Left([Primary_Image], instr([Primary_Image], "_")-1) & Mid([Primary_Image], instrrev([Primary_Image], "."))
WHERE instr([Primary_Image], "_") > 0
0
Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

 
LVL 50

Expert Comment

by:Gustav Brock
ID: 39783265
You could use this expression:

SET Primary_Image = Left([Primary_Image], InStr([Primary_Image], "_") - 1 & ".jpg"

/gustav
0
 
LVL 47

Expert Comment

by:Dale Fye (Access MVP)
ID: 39783312
always trying to make things easier, aren't you Gustav?

I guess I'm just so used to pulling something off the front, and something off the back that it never occurred to me to do it the simple way (although you forgot the closing paren as well.

@fordraiders

If you are going to do it that way, I would modify the WHERE clause to look something like:

WHERE InStr([Primary_Image], "_") > 0  AND InStr([Primary_Image], ".jpg") > 0

This will make sure you do not inadvertently change the extension of some other image type.
0
 
LVL 3

Author Closing Comment

by:fordraiders
ID: 39785441
Thanks
0

Featured Post

Secure Your Active Directory - April 20, 2017

Active Directory plays a critical role in your company’s IT infrastructure and keeping it secure in today’s hacker-infested world is a must.
Microsoft published 300+ pages of guidance, but who has the time, money, and resources to implement? Register now to find an easier way.

Question has a verified solution.

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

Overview: This article:       (a) explains one principle method to cross-reference invoice items in Quickbooks®       (b) explores the reasons one might need to cross-reference invoice items       (c) provides a sample process for creating a M…
Phishing attempts can come in all forms, shapes and sizes. No matter how familiar you think you are with them, always remember to take extra precaution when opening an email with attachments or links.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

740 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