Solved

Right 7 of sequence unless end alpha

Posted on 2013-01-24
15
332 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
How our DevOps Teams Maximize Uptime

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

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

This article describes how to use the timestamp of existing data in a database to allow Tableau to calculate the prior work day instead of relying on case statements or if statements to calculate the days of the week.
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
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…

726 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