Results 1 to 5 of 5
  1. #1
    Join Date
    Jun 2004
    Posts
    6

    Unanswered: 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?

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    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;

  3. #3
    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.

  4. #4
    Join Date
    Feb 2004
    Location
    In front of the computer
    Posts
    15,579
    Provided Answers: 54
    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

  5. #5
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •