KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Using the '@' Character as a Literal in a Query
PRODUCT: 4D | VERSION: 13.0 | PLATFORM: Mac & Win
Published On: March 30, 2012

When performing a query in 4D, the @ character is interpreted as a wildcard. For example, all [Customers] whose last name starts with an "a" can be queried as follows:

QUERY([Customers];[Customers]Last_Name="a@")


But what happens if a query for an exact match of an email address is needed? For example, the following query will not change the selection to records only with the the email customer@company.com:

QUERY([Customers];[Customers]Email="customer@company.com")


Instead, the above query will return any record whose email starts with "customer" and ends with "company.com". This would include emails such as customer1@company.com or customer@ABcompany.com, etc.

There are a few ways around this. One way is to change a setting via the Database Settings window:

Selecting "Consider @ as a wildcard only when at the beginning or end of text patterns" will make queries for an exact match of email addresses work. The earlier query will now return records only with the email field equal to customer@company.com with this option selected. Meaning records with the email equal to customer1@company.com or similar would no longer be included in the selection.

Another way to get an exact match for the email address customer@company.com would be to use the Match regex command as shown:
QUERY BY FORMULA([Customers];Match regex("customer@company.com";[Customers]Email))