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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String Comparison 1

Status
Not open for further replies.

dmears1

Technical User
Jun 18, 2003
208
US
I need to search a table for certain area codes. Because the office does not have a uniform way of entering phone numbers into the database, some are entered as (555)555-5555 and others as 555-555-5555.
I have a select statement in which I want to return phone numbers beginning with a certain area code indepent of how the phone number was entered.
I've tried the following:

Code:
SELECT customers_telephone FROM customers WHERE customers_groups_id = 3 AND customers_telephone
like '(310)%' OR customers_telephone
like '310%'

but it does not work. If I remove the OR and search for only phone numbers with () or without()the SQL works.

Any ideas on how I can implement this would be greatly appreciated.

 
Thanks for the reply.
I know that the AND operator has a higher precendence than OR. The example above was the best way I could think of explaining what I want to achieve.

 
How about this?

Code:
SELECT customers_telephone FROM customers WHERE customers_groups_id = 3 AND (customers_telephone
like '(310)%' OR customers_telephone
like '310%')
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top