2

I have a table with a string field containing location information. I want to be able to query this table and retrieve all of the tags matching the format xxxxxxAA where xxxxxx is a 6-digit number and AA is two alphabetic characters.

Is there a method of querying this using SQL or is this something that I need to do in VBA?

Sample data:

BGS5 PM RGP5
022051PM
022201PM
030539PM
WAS3N
179546MM

And I want to return the following without knowing the values:

022051PM
022201PM
030539PM
179546MM

thanks in advance Jason

1 Answer 1

1

You can use a query with a Like comparison in the WHERE clause.

SELECT y.text_field
FROM YourTable AS y
WHERE y.text_field Like '######[A-Z][A-Z]'

The # matches a digit.

[A-Z] matches one character from a character class consisting of only letters. That character class is actually upper case letters. However, the comparison is case-insensitive, so will match lower case letters, too.

Sign up to request clarification or add additional context in comments.

1 Comment

If your source data is a native MS Access table, query criteria are always case-insensitive. Option Compare Binary only applies to VBA code such as If text_field Like "######[A-Z][A-Z]" Then....

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.