Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find match on first 3 positions of a field

Status
Not open for further replies.

Bennie47250

Programmer
Nov 8, 2001
515
0
0
US
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
 
How about:

[pre]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')[/pre]

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
try
Code:
Select * From TableName
Where IsNumeric (Mid(SerialNo, 1, 1) ) = 0
and   IsNumeric (Mid(SerialNo, 2, 1) ) = 0
and   IsNumeric (Mid(SerialNo, 3, 1) ) = 0


 
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

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

Have fun.

---- Andy

There is a great need for a sarcasm font.
 
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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top