Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 758503
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T15:29:11+00:00 2026-05-14T15:29:11+00:00

I’ve a table with about 130 000 records with telephonenumbers. The numbers are all

  • 0

I’ve a table with about 130 000 records with telephonenumbers. The numbers are all formated like this +4311234567. The numbers always include international country code, local area code and then the phonenumber and sometimes an extension.

There is a webservice which checks for the caller’s number in the table. That service works already. But now the client wants that also if someone calls from a company which number is already in the database but not his extension, that the service will return some result.

Example for table.

   **id** | **telephonenumber**    | **name**   
|    1    | +431234567             | company A  
|    2    | +431234567890          |  employee in company A  
|    3    | +4398765432            | company b 

now if somebody from company A calls with a different extension for example +43123456777, than it should return id1. But the problem is, that I don’t know how many digits the extensions have. It could have 3,4 or more digits.

Are there any patterns for string kind of matchings?

The data is stored in a sql2005 database.

Thanks

EDIT:
The telephonenumbers i am getting from a crm system. I’ve talked with the admin of the crm and he is trying to send me the data in a different format.

   **id** | **telephonenumber** |**extension**   | **name**   
|    1    | +431234567          |                | company A  
|    2    | +431234567          |      890       |  employee in company A  
|    3    | +4398765432         |                | company b 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T15:29:12+00:00Added an answer on May 14, 2026 at 3:29 pm

    Given that the number of digits in the extension can be different for each company and the number of digits in the number could be different for each country and area code, this is a tricky problem to do efficiently.

    Even if you get the data table split into base number and extension, you still have to split the incoming number into base number and extension, which I actually think complicates things.

    What I would be inclined to try is:

    Original format

    1. Try to match the incoming number with the database.
      • If it matches one record, you have your answer – a specific person.
      • If it matches more than one record, something has gone wrong, so fail.
      • Otherwise, you have to find the company:
    2. Strip off the trailing digit from the incoming number and try to match this with the database again.
      • If the number of digits drops below a threshold (probably 6 digits) then your search should probably fail. This is just to limit the number of database searches performed when the number isn’t going to be found.
      • If it matches no records, then you need to try this step again.
      • If it matches more than one record, something has gone wrong, so fail.
      • If it matches exactly one record, you have your next best answer – the company.

    For example, searching for “+43123456777”:

    • +43123456777 matches 0 entries.
    • +4312345677 matches 0 entries.
    • +431234567 matches 1 entry: “Company A”

    The main failure mode of this approach is if a company has variable length extension numbers. For instance consider what happens if both 431234567890 and 43123456789 are valid numbers but only the second one is in the database. If the incoming number is 431234567890, then 43123456789 will be matched in error.

    Split format

    This is a little more complex, but more robust.

    1. Try to match the incoming number with the database.
      • If it matches one record, you have your answer – the company.
      • If it matches more than one record, match the entry without an extension and you have found the company.
      • Otherwise, you have to find the base company number and extension:
    2. Strip off the trailing digit from the incoming number and try to match this with the database again.
      • If the number of digits drops below a threshold (probably 6 digits) then your search should probably fail. This is just to limit the number of database searches performed when the number isn’t going to be found.
      • If it matches no records, then you need to try this step again.
      • If it matches one record, then you have found your answer – the company.
      • If it matches more than one record, then you have found the base number of the company and thus now know the extension, so can try to look up the specific person:
    3. Strip the base number from the start of the original incoming number and use this to search the extensions of the records with that base number.
      • If it matches exactly one record, you have found a specific person.
      • If it doesn’t match a specific person, match the entry without an extension and you have found the company.

    For example, searching for “+43123456777”:

    • +43123456777 matches 0 entries.
    • +4312345677 matches 0 entries.
    • +431234567 matches 2 entries: “empty:Company A” & “890:employee in company A”
    • Within these two matches “77” matches nothing, so return the empty extension: “Company A”.

    Implementation notes

    This algorithm, as noted above, does have some efficiency problems. If the database lookup is expensive, it has a linear cost related to the length of the telephone number, especially in the case where no similar numbers exist in the database (for example, if the incoming number is from Kazakhstan, but there are no Kazakhstan numbers in the datsbase *8′).

    You could add some optimisations relatively easily though. If most of the companies you deal with use 3 or 4 digit extensions, you could start by stripping, say, 4 digits off the end and then doing a binary chop, until you reach an answer. This would reduce a 15 digit number to 4 or 5 in many cases and at most 6 lookups.

    Also, every time you narrow the selection, you could select only within the previous selection rather than having to select within the whole database.

    Additional implementation notes

    Having finally worked out how Unreason’s answer works, I can see that is a much simpler, more elegant solution. I wish I’d though of the simplicity of simply looking for the database number in the incoming number rather than the other way around.

    My only concern is that performing this on every telephonenumber in the database might impose excessive demands on the server. I would suggest benchmarking that solution under maximum stress and see if it causes problems. If not, fine – use that. If it does, consider implementing the simple form of my algorithm and doing the stress tests again. If the performance is still too low, try my binary search suggestion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
For some reason, after submitting a string like this Jack’s Spindle from a text
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have some data like this: 1 2 3 4 5 9 2 6
I have two tables with like below codes: Table: Accounts id | username |
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.