Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Right 7 of sequence unless end alpha

Posted on 2013-01-24
15
Medium Priority
?
336 Views
Last Modified: 2013-01-28
Ok I have characters like this: CG125BR8114662 OR CG125BR8114662D

I would like the right 7 if no end alpha character exists or if end alpha exists then the same without the end alpha.

I tried:
right(
trim(
iif(
NOT isnumeric(right([VIN],1),
left([VIN],len([VIN])-1),
[VIN])
)
,
7)

I am in access query grid
0
Comment
Question by:PeterBaileyUk
[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
  • 8
  • 5
15 Comments
 
LVL 61

Expert Comment

by:mbizup
ID: 38814268
try this:

Right(iif(ISNumeric(Right(VIN,1) = True, VIN, LEFT(VIN, Len(VIN) -1)),7)

Open in new window

0
 
LVL 61

Accepted Solution

by:
mbizup earned 1000 total points
ID: 38814276
Opps - Missed a ):

Right(iif(ISNumeric(Right(VIN,1)) = True, VIN, LEFT(VIN, Len(VIN) -1)),7)

Open in new window

0
 
LVL 120

Assisted Solution

by:Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1) earned 1000 total points
ID: 38814278
try this

Right(IIf(Not IsNumeric(Right([VIN],1)),Left([VIN],Len([Vin])-1),[VIN]),7)
0
Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

 

Author Comment

by:PeterBaileyUk
ID: 38814378
its failing on arguments
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38814385
Try this again... This seems to test okay in VBA:

Right(iif(ISNumeric(Right(VIN,1) = True, VIN, LEFT(VIN, Len(VIN) -1)),7)
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38814396
Also,  if VIN can be null or less than 7 letters:


IIF(Len(VIN & "") < 7, "VIN Too Short", Right(iif(ISNumeric(Right(VIN,1) = True, VIN, LEFT(VIN, Len(VIN) -1)),7))

Open in new window

0
 

Author Comment

by:PeterBaileyUk
ID: 38814402
thx
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38814425
Correction:

IIF(LEN(VIN & "") < 7, "VIN Too Short",  Right(iif(  ISNumeric(Right(VIN,1)) = True, VIN, LEFT(VIN, Len(VIN) -1)),7))

Open in new window

0
 
LVL 61

Expert Comment

by:mbizup
ID: 38814439
Can you try my comment at http:#a38814276 again?

It works identically to the later one that you selected from Capricorn1  (they are equivalent syntaxes)
0
 

Author Comment

by:PeterBaileyUk
ID: 38814904
I will try the other too i noticed also that the result sometimes gives an alpha at the start of the solution. it would be better if the result didnt contain an alpha at the beginning. ex: C122502

the ultimate goal will be to sort the sequence numbers from a min and a max.
0
 

Author Comment

by:PeterBaileyUk
ID: 38814934
i can always post a new question re stripping the front or any alpha from result @mbizup as i notice i didnt distribute the points sorry.
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38814987
Both solutions will simply give you the right-most 7 characters without a trailing non-numeric character .. that was based on the wording of your original post.

However, if you want to strip out an unknown number of alpha characters from both the beginning and the end, you might have to use VBA.  Check out the solution here:
http://www.utteraccess.com/forum/Removing-alphanumeric-ch-t1898931.html

That removes non-numbers, leaving behind a numeric string that can be any length.

Edit --
Sorry.. I'm misreading that one it removes non-alpha numeric characters, but you can adjust the criteria used in he code to exclude anything out that is not a number (Ascii values between 48 and 57)
0
 

Author Comment

by:PeterBaileyUk
ID: 38815150
the criteria at first was correct, i dont know if stripping out an alpha in the middle or elsewhere will serve purpose. any number upto 7 numerals could be surrounded by alpha so the left and right alpha is all i want to remove. the numeral part will be the serial number of the vehicle, if i get a vin with a character in the middle of that number the vin is wrong so i wouldnt filter on that.

I wonder if the code can be honed to strip the left if one exists after the first removal without excessive actions
0
 
LVL 61

Expert Comment

by:mbizup
ID: 38815240
Thats doable, but it will only cover one character to the left and one to the right.  The expression would also get quite complicated, so I'd suggest using a VBA function:

Function GetNum(VIN)
   Dim sFirst As String
   GetNum = Right(IIf(IsNumeric(Right(VIN, 1)) = True, VIN, Left(VIN, Len(VIN) - 1)), 7)
   sFirst = Left(GetNum, 1)
   GetNum = IIf(IsNumeric(sFirst) = True, GetNum, Right(GetNum, Len(GetNum) - 1))
End Function

Open in new window


and call it from your query:

SELECT GetNum(VIN) AS ModifiedVIN
FROM...

Open in new window

0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
With Microsoft Access, learn how to start a database in different ways and produce different start-up actions allowing you to use a single database to perform multiple tasks. Specify a start-up form through options: Specify an Autoexec macro: Us…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

636 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