AlphaPress Publishing
P.O. Box 5942 Albany, NY 12205
Tel: 518-250-3890
Email: alphapress@hotmail.com  


  
Click to buy this book from Amazon

Section Menu 

News

Pindaro is now working on a comprehensive book on SQL Server 2014.  For any comments you can email the author at alphapress@hotmail.com.

  

 

 

Use Like to test for the presence of numbers in a field value

To contact the author click here

This article is from the book "Access 2007 Pure SQL

To download the sample database click here


Use LIKE to test a field for the presence of numbers 

Check for the presence of numbers in a city field

Discussion:

Now, what if someone entered some city names and did not pay attention and as he was typing, he mingled some numbers with the name of the city?  For example, he might have entered "New 9York".  How can we check a field for the presence of numbers within text strings?  The answer is by using the LIKE operator, the [ ] wildcard character for ranges, and the * wildcard character as in the code below.  Notice we use the [ ] to check for any number between 0 and 9.  In addition, we use the * twice to look for the presence of a number at any part of the field including the end and the beginning of its value.  We actually caught two records with numbers mistyped in them. 

Code:

SELECT lastname, firstname, city, orderdate

FROM tbls_CustomerOrders

WHERE (city LIKE "*[0-9]*")
 

Result: