If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > Comparing Tables By The First Seven Digits

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-02-04, 16:19
carlm carlm is offline
Registered User
 
Join Date: Jun 2004
Posts: 6
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?
Reply With Quote
  #2 (permalink)  
Old 06-02-04, 16:35
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
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;
Reply With Quote
  #3 (permalink)  
Old 06-02-04, 16:53
carlm carlm is offline
Registered User
 
Join Date: Jun 2004
Posts: 6
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.

Last edited by carlm; 06-02-04 at 17:13.
Reply With Quote
  #4 (permalink)  
Old 06-03-04, 02:49
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,605
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
Reply With Quote
  #5 (permalink)  
Old 06-03-04, 13:14
carlm carlm is offline
Registered User
 
Join Date: Jun 2004
Posts: 6
Quote:
Originally Posted by Pat Phelan
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On