Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What's the SQL syntax for specifying only certain field characters?

Status
Not open for further replies.

SirPaladin

Programmer
Jul 9, 1999
32
0
0
US
For example, I need to use SQL to select records of only a particular area code. My current SQL statement (to find a specific phone number. I'm concatonating several search parameters so SQLString already contains the "SELECT * FROM [Companies] WHERE [other parameters]) looks like this:

SQLString$ = SQLString$ & " AND (([Companies].[MainPhone] = '" & Trim(Text1(12).Text) & "')"

I don't want to use just a simple "LIKE" clause that looks anywhere in the field because then l could end up with records that contain the number within it that are the same as the area code [ie. looking for area code "972" would grab 972-555-1212 as well as 214-534-9720]

So how do I specify that I only want to find records that match my search criteria in the first 3 characters of a field?
 
It should work fine if you do something like this:

SELECT * FROM [Companies]
WHERE [Companies].[MainPhone]
LIKE "972-%"

This should only bring back records that have a phone number that starts with 972-
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top