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
Solved

Filter column string with Right function?

Posted on 2013-12-15
21
523 Views
Last Modified: 2013-12-15
I am trying to strip off the .jpg extension in my filenames... but the query I am using returns nothing.

How do I filter a column full of serialized photo file names with Right function?

I have a column full of filenames of serialized photos:
[FileName]
d3x_6013.jpg
d3x_6014.jpg
d3x_6015.jpg

I simply want to remove the .jpg extension using the Right function.

When I use the following formula in a query using the Right function in the criteria field it returns nothing?

Right([FileName],8)

(Ideally, I would like a query that would also strip out the "d3x" off the beginning of the filename as well, so I am left with just the numbers.)

-Greg
0
Comment
Question by:geekmee2
  • 10
  • 7
  • 4
21 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39720711
try this query

select [FileName], val(mid([FileName],5))
from tablex


or this

select [FileName], mid([FileName],5,Instr([FileName],".")-5)
from tablex
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39720719
The right function returns the selected number of characters that you passed in , count in from the right. RIGHT([FileName],4) would give you .jpg

If the filename is always in the format you suggest, then LEFT([Filename],Len(Filename]-4) will give you what you want.


Kelvin
0
 

Author Comment

by:geekmee2
ID: 39720741
Left([Filename],"Len[Filename]-4") is giving me a "Data type mismatch" error?
0
Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39720742
@geekmee2

did you try the query I posted?
0
 

Author Comment

by:geekmee2
ID: 39720745
Yes, Capricorn.... It gave me an error of Invalid syntax or I needed to put quotes around text.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39720747
what do you mean?

how are you using what  I posted?
0
 

Author Comment

by:geekmee2
ID: 39720748
I copy and pasted.... into the criteria field in the query.
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39720750
<I copy and pasted>  where did you paste ?

post what ever you have going.


<.... into the criteria field in the query. > that is not correct
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39720757
Left([Filename],"Len[Filename]-4") should be without the quotes

Kelvin
0
 

Author Comment

by:geekmee2
ID: 39720759
Invalid Syntax Error [see screenshot]
InvalidSyntax-Error.jpg
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 39720761
<.... into the criteria field in the query. > that is not correct

it should be like this


            field    [FileName]  |  val(mid([FileName],5))
table name                         |
criteria



x
0
 

Author Comment

by:geekmee2
ID: 39720765
Kelvin, I tried, but the system adds the quotes (?).
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39720769
Ah should be
Left([Filename],Len([Filename])-4)

Kelvin
0
 

Author Comment

by:geekmee2
ID: 39720771
Capricorn1:  Yes, that worked!.... Thank you for the screenshot.

But please help me understand what this formula is doing?

Was I using the wrong function (Left) to accomplish this in the criteria field?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39720776
Left("d3x_6013.jpg",4) will give you  d3x_

Left("d3x_6013.jpg",Len("d3x_6013.jpg")-4)    > will give you  6013.jpg



Mid("d3x_6013.jpg",5) will give you 6013.jpg

Val(6013.jpg)  will give you  6013

so the combination  

val(Mid("d3x_6013.jpg",5) ) will give 6013


better look in the VBA help file  for the Left, Mid, Right function and the VAL function
0
 

Author Comment

by:geekmee2
ID: 39720787
Ok. so the the Mid function returns results to the Val function, and the Val function acts on what was passed to it, and gives me the final desired result.

So the Left function only gets me part of the way there, or my first request.

But still don't understand why the Left function in the criteria field was returning a blank set of results?
0
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 39720796
why a B grade ?
0
 

Author Comment

by:geekmee2
ID: 39720810
I did offer 500 points...for the answer, which you did give, promptly.

I still had questions, but you did offer extended breakdown of the other functions, and you did point me to additional resources, VBA helpfile.

I can change it to an A if you would like, I try and reserve A for exceptional effort.

As a trainer, I have feel the value of an answer is tailoring the answer to the knowledge level of the student... which I feel your screenshot accomplished.

How do go about revising the grade to an A?
0
 

Author Comment

by:geekmee2
ID: 39720816
I am happy to change it to an A if you like...

But in reviewing the posting, originally I was trying to use the Right function to achieve my goal.  You gave me another solution, which was better.

But for me, an A means there was no way to improve on the delivery of the answer.  
Here my gut reaction was "what am I doing wrong."   While the answer was correct, I was still left with the question of what I was doing wrong.

For me, an A would have helped me understand the flaw of my approach, which would have expanded my knowledge and understanding of using your (a better) approach.

Hope that helps.

-Greg
0
 
LVL 22

Expert Comment

by:Kelvin Sparks
ID: 39720818
Hmmmm,

This is a site for answers - not a training site, although many experts such as Capricorn1 so the extra mile and offers extra advice and reasoning. An A is usually given for a answer that fully solves the problem (whether or not training is provided).

Kelvin
0
 

Author Comment

by:geekmee2
ID: 39720822
Understood.... My bad.  I guess I need to manage my expectations.

I can change the grade to an A.... for it was very correct.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction The Visual Basic for Applications (VBA) language is at the heart of every application that you write. It is your key to taking Access beyond the world of wizards into a world where anything is possible. This article introduces you to…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

765 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