INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Find match on first 3 positions of a field

Find match on first 3 positions of a field

(OP)
Have a 10 position text field that stores our serial numbers. The first 3 positions of the serial number can contain all digits, all alpha or mixed alpha and digits.

Need a query that will only select the records if the leading 3 characters are each alpha.

Tried several different things but can’t seem to get it to work.
Thanks

RE: Find match on first 3 positions of a field

How about:

Select * From MyTable
Where Mid(UCase(SerialNo), 1, 1) IN ('A','B','C',...,'Z')
  AND Mid(UCase(SerialNo), 2, 1) IN ('A','B','C',...,'Z')
  AND Mid(UCase(SerialNo), 3, 1) IN ('A','B','C',...,'Z') 

Have fun.

---- Andy

There is a great need for a sarcasm font.

RE: Find match on first 3 positions of a field

try

CODE --> SQL

Select * From TableName
Where IsNumeric (Mid(SerialNo, 1, 1) ) = 0
and   IsNumeric (Mid(SerialNo, 2, 1) ) = 0
and   IsNumeric (Mid(SerialNo, 3, 1) ) = 0 


RE: Find match on first 3 positions of a field

(OP)
I have done something like what Andy suggested but I performed the Mid function on each one of the first 3 positions and used this as the select criteria Like "[A-Z}" I think it basically the same. Using the range help with the typing.

A colleague on mine who is really good with SQL came up with this where ltrim(substring([SN_serial_num], 1, 3)) NOT LIKE '%[^A-Z]%' Was hoping to find the correct syntax to use in Access

RE: Find match on first 3 positions of a field

Give PWise's suggestion a try. It should work OK in Access.

Have fun.

---- Andy

There is a great need for a sarcasm font.

RE: Find match on first 3 positions of a field

I was expecting you could use

CODE --> Expression

IsNumeric(Left(SerialNo,3)) 
however found this

CODE --> debug

? Isnumeric("1E1")
True 

Duane
Hook'D on Access
MS Access MVP

RE: Find match on first 3 positions of a field

CODE -->

Like "[a-Z][a-Z][a-Z]*" 

Doesn't feel 'elegant' having to repeat the same thing for all 3 characters, however - it does work.
You could of course build the SQL 'LIKE' string using VBA to make it variable / dynamic.
(Mixed capitalisation ensures upper AND lower returns).


ATB,

Darrylles

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close