Solved

Right 7 of sequence unless end alpha

Posted on 2013-01-24
15
329 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
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.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Experts-Exchange is a great place to come for help with solutions for your database issues, and many problems are resolved within minutes of being posted.  Others take a little more time and effort and often providing a sample database is very helpf…
'Between' is such a common word we rarely think about it but in SQL it has a very specific definition we should be aware of. While most database vendors will have their own unique phrases to describe it (see references at end) the concept in common …
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

920 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

11 Experts available now in Live!

Get 1:1 Help Now