Solved

Compare only last 4 characters of phone number in SQL query

Posted on 2011-02-20
3
457 Views
Last Modified: 2012-05-11
I have the following SQl query I'm running against two tables in an Access 2007 database:

SELECT ContactPhone.Item_ID, ContactPhone.Last_Name, ContactPhone.First_Name, ContactPhone.Work_Phone, ContactPhone.[1st_Choice], ContactPhone.[2nd_Choice], ContactPhone.[3rd_Choice], ContactPhone.Comments
FROM ContactPhone LEFT JOIN onlyDCS ON ContactPhone.Work_Phone=onlyDCS.Work_Phone
WHERE (((onlyDCS.Work_Phone) Is Null));


I want to just use a substring compare of the last  four character of the "Work_Phone" from both tables.

example of the Work_Phone  data

555-1234

just need to compare

1234

Thanks!!
0
Comment
Question by:rkckjk
  • 2
3 Comments
 
LVL 120

Expert Comment

by:Rey Obrero (Capricorn1)
ID: 34937695
you can only do this in the sql view of the query

select * from ContactPhone
where  right([ContactPhone ].[Work_Phone],4)=right([onlyDCS].[Work_Phone],4)
0
 
LVL 120

Accepted Solution

by:
Rey Obrero (Capricorn1) earned 500 total points
ID: 34937703
SELECT ContactPhone.Item_ID, ContactPhone.Last_Name, ContactPhone.First_Name, ContactPhone.Work_Phone, ContactPhone.[1st_Choice], ContactPhone.[2nd_Choice], ContactPhone.[3rd_Choice], ContactPhone.Comments
FROM ContactPhone, onlyDCS
where  right([ContactPhone ].[Work_Phone],4)=right([onlyDCS].[Work_Phone],4)
 
0
 
LVL 2

Author Closing Comment

by:rkckjk
ID: 34937732
thanks
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
In Microsoft Access, learn how to use Dlookup and other domain aggregate functions and one method of specifying a string value within a string. Specify the first argument, which is the expression to be returned: Specify the second argument, which …
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question