Solved

Right 7 of sequence unless end alpha

Posted on 2013-01-24
15
330 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
  • 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 250 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 250 total points
ID: 38814278
try this

Right(IIf(Not IsNumeric(Right([VIN],1)),Left([VIN],Len([Vin])-1),[VIN]),7)
0
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

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

Suggested Solutions

Title # Comments Views Activity
Dlookup MSACCESS 5 25
Mysql Left Join Case 10 55
split XML field into many fields from MS Access 21 25
access query to sql server 3 21
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
A simple tool to export all objects of two Access files as text and compare it with Meld, a free diff tool.
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 …

809 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