Solved

Right 7 of sequence unless end alpha

Posted on 2013-01-24
15
328 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 119

Assisted Solution

by:Rey Obrero
Rey Obrero earned 250 total points
ID: 38814278
try this

Right(IIf(Not IsNumeric(Right([VIN],1)),Left([VIN],Len([Vin])-1),[VIN]),7)
0
 

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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
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…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now