Tuesday, March 27, 2012

Comparing Tables By The First Seven Digits

I have one database called CAM and two tables. Table one is called WIRELESS and has one field called PHONE with 7 digit phone numbers. Table two is called MASTER and has one field called PHONE with ten digit phone numbers.

I want to compare table WIRELESS to MASTER. I want to compare the 7 digit phone number in WIRELESS table to the first 7 digits in the MASTER table.

Any idea on what the query syntax would be for this?Use (for Oracle) SUBSTR function which will return first 7 digits; something like

SELECT w.phone wireless_phone, SUBSTR(m.phone, 1, 7) master_phone
FROM wireless w, master m
WHERE w.phone_id = m.phone_id;|||I tried the following query

select wireless.wirelessphone, SUBSTR(master.phone, 1,7)
from wireless w, master m
where w.wirelessphone_id = m.phone_id;

and SQL replied that it is not a valid function name.|||What SQL database engine are you using? I'd try using substring as well as substr, since most of the engines that I can think of support the Substring function.

-PatP|||What SQL database engine are you using? I'd try using substring as well as substr, since most of the engines that I can think of support the Substring function.

-PatP

I am using SQL 2000

No comments:

Post a Comment