INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• 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.

# 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

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 

### 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.

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:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!