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 find blank spaces in fields

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 spaces 

Check for the presence of blank spaces in the city field

Discussion:

The same supervisor comes back and says she needs a report of customers from certain cities.  This time you are wise enough to know that to get the right results you need to check for spaces first.  Then however, you reason that some city names do contain spaces.  For example, New York contains a space and Los Angeles contains a space.  In addition, you realize that the trim() function is good enough for leading and trailing spaces.  What if you have a space right in the middle of the word?  You can actually look for spaces using the LIKE operator with the * wildcard character.  In this example, we are looking for two spaces in any part of the field value.  To achieve this we use the * three times.  You can test for one space using two asterisks ("* *").  We found two city names with two blank spaces as you can see in the figure below.    

Code:

SELECT lastname, firstname, city, orderdate

FROM tbls_CustomerOrders

WHERE (city LIKE "* * *") 

Result: