Link to home
Start Free TrialLog in
Avatar of Richard Kreidl
Richard KreidlFlag for United States of America

asked on

Compare only last 4 characters of phone number in SQL query

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!!
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

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)
ASKER CERTIFIED SOLUTION
Avatar of Rey Obrero (Capricorn1)
Rey Obrero (Capricorn1)
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Richard Kreidl

ASKER

thanks