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


  

Section Menu 

Are you a University or College bookstore and want to order multiple books?  Email us at alphapress@hotmail.com or call us at 518-250-3890.  We will be happy to talk to you.  

Are you a professor and you need a sample copy?  We will be happy to send you a pdf or printed copy!  Email us at alphapress@hotmail.com.

Are you outside the United States?  We can ship multiple books worldwide in most countries.

  

 

 

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: