Welcome to the dBforums forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

If you prefer not to see double-underlined words and corresponding ads, place your cursor
here for ContentLink opt out.

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, 17: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, 17:35
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 2,717
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, 17: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 18:13.
Reply With Quote
  #4 (permalink)  
Old 06-03-04, 03:49
Pat Phelan Pat Phelan is online now
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 9,572
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, 14: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

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