Solved

Compare only last 4 characters of phone number in SQL query

Posted on 2011-02-20
3
453 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 119

Expert Comment

by:Rey Obrero
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 119

Accepted Solution

by:
Rey Obrero 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

Get up to 2TB FREE CLOUD per backup license!

An exclusive Black Friday offer just for Expert Exchange audience! Buy any of our top-rated backup solutions & get up to 2TB free cloud per system! Perform local & cloud backup in the same step, and restore instantly—anytime, anywhere. Grab this deal now before it disappears!

Join & Write a Comment

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
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 …

758 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now