Solved

Filter column string with Right function?

Posted on 2013-12-15
21
518 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
Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

 
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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

In a multiple monitor setup, if you don't want to use AutoCenter to position your popup forms, you have a problem: where will they appear?  Sometimes you may have an additional problem: where the devil did they go?  If you last had a popup form open…
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.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
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…

831 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