whitespace query mystery

crib bar 841 Reputation points
2024-07-26T08:27:49.12+00:00

I am trying to identify ‘mismatches’ between a table of valid email addresses, and an employees table with an email address field. I’ve just been using the standard ‘find unmatched query wizard’ in Microsoft Access which has identified several problematic records that need resolving. This is not a relational database behind a front end application, just 2 extracts of data imported into Access for cross-referencing.

Most of the mismatches seem to be due to whitespace related issues, e.g. leading or trailing whitespace – however, whilst the spaces are apparent visually when I click in the field from the ‘find unmatched query wizard’ results, I am struggling to pick them up via a SELECT query, so I am now wondering if they are technically considered something different to blank spaces (tabs?).

I am using:

SELECT MyTable.Email_Address

FROM MyTable

WHERE MyTable.Email_Address LIKE ' %' OR MyTable.Email_Address LIKE '% '

And for whatever reason, the same mismatches are not being returned in the results (I’ve even tried double/treble spaces). In case it may be influencing anything, MyTable.Email_Address is the data type Short Text. Are there any other clever techniques that can identify what exactly Access considers these leading/trailing whitespaces as, or a better query to help find anything whitespace related leading/trailing the address?

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
4,889 questions
Access
Access
A family of Microsoft relational database management systems designed for ease of use.
389 questions
Access Development
Access Development
Access: A family of Microsoft relational database management systems designed for ease of use.Development: The process of researching, productizing, and refining new or existing technologies.
877 questions
Office Management
Office Management
Office: A suite of Microsoft productivity software that supports common business tasks, including word processing, email, presentations, and data management and analysis.Management: The act or process of organizing, handling, directing or controlling something.
2,146 questions
0 comments No comments
{count} votes

Accepted answer
  1. Duane Hookom 75 Reputation points
    2024-07-26T18:35:08.5833333+00:00

    Use a criteria of:

    Like " "

    0 comments No comments

2 additional answers

Sort by: Most helpful
  1. Viorel 117.2K Reputation points
    2024-07-27T04:44:33.03+00:00

    The first and last character is usually a letter, therefore you can use where Email_Address not like '[a-z]%[a-z]' to include the problematic entries that start or end with various spaces. In case of Access SQL, use “*” instead of “%”.

    In Access you can also use Regular Expressions and VBA for more sophisticated filtering.

    1 person found this answer helpful.
    0 comments No comments

  2. Ken Sheridan 2,841 Reputation points
    2024-07-27T15:42:37.0266667+00:00

    You can identify a string expression which includes leading or trailing spaces by comparing the length of the expression with the length of the trimmed expression, e.g.

     

    x = "ABC"

    y = "ABC "

    z = " ABC"

    ? Len(x) = Len(Trim(x))

    True

    ? Len(y) = Len(Trim(y))

    False

    ? Len(z) = Len(Trim(z))

    False

     

    To identify a string expression which includes one or more spaces at any positions call the Replace function rather than the Trim function, e.g.

     

    a = "ABC"

    b = "AB C"

    ? Len(a) = Len(Replace(a," ",""))

    True

    ? Len(b) = Len(Replace(b," ",""))

    False  

    or call the Instr function:

     

    a = "ABC"

    b = "AB C"

    ? Instr(a," ")=0

    True

    ? Instr(b," ")=0

    False

    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.