Solved

SQL Match Dialled Number to International Dialling Code

Posted on 2011-09-08
8
275 Views
Last Modified: 2012-08-13
Hi
I have SQL 2005.
Table A is a log of all dialled telephone numbers
Table B is a list of all International Dialling Codes and their associated chargebands (e.g A or B or C etc)
In Table A (the log) I have a column named 'DialledNumber' (nvarchar)
In Table B (list of International Dialling Codes) I have a column named 'DiallingCode' (nvarchar)
I want to create a view that list all rows in Table A (the log) and outer joins Table B by comparing the DialledNumber in Table A to the DiallingCode in Table B to returns the ChargeBand in Table B.
I have tried several different things with no luck.
Can anyone help?
Thanks!
0
Comment
Question by:nsp123
  • 4
  • 2
  • 2
8 Comments
 

Author Comment

by:nsp123
ID: 36501845
Further info!:
The dialled number may look like this:
441582666666
OR
3462222222
etc
I want to compare the dialled number to the list of dialling codes but bometimes a country's dialling code is 1, 2, 3 or 4 digits long:
E.g.
USA = 1
UK = 44
Icelnd = 354
Jamaica = 1876
etc..
0
 
LVL 142

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 36501881
to identify the row for the longest dialled code for a given number:
select top 1 * from B where 44158266 like DiallingCode + '%' order by length(DiallingCode) desc
0
 
LVL 5

Expert Comment

by:zvytas
ID: 36501894
angelll - SQL Server 2005 does not support "length" function, the query should be as follows:

select top 1 * from B where 44158266 like DiallingCode + '%' order by len(DiallingCode) desc
0
 

Author Comment

by:nsp123
ID: 36501923
Hi angellll and zvytas,
Thanks for your quick replies.
I dont think I have made my question very clear...
What we have is a table that contains the log of all dialled telephone numbers, these dialled numbers can be anything (I included 441528666 only as an example of a dialled number), we have a 2nd table that contains all the countries and their international dialling codes and their chargeband letters.
What I wanted was to compare the dialled number in the first table to the dialling codes in the 2nd table and return the associated chargeband for that dialled number..
So the dialled number can be any number of digits, the dialling code is likely to be up to 4 digits, the first part of the dialled number needs to be compared to the dialling code so I can retrieve the chargeband information.
I was hoping to write a view to do this...
Does this make sense?
0
Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

 
LVL 5

Assisted Solution

by:zvytas
zvytas earned 250 total points
ID: 36501950
select *
from log
   left join codes on log.number like codes.number + '%'
0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 250 total points
ID: 36502002
yes, you have made the problem clear, but my suggestion was not ...

select a.*
, (select top 1 b.charge_band from B where a.dialled_number like DiallingCode + '%' order by len(DiallingCode) desc ) assigned_charge_band
 from A

Open in new window

0
 

Author Comment

by:nsp123
ID: 36528751
Thanks I will take a look at this asap and let you know
0
 

Author Closing Comment

by:nsp123
ID: 36585924
Thank you zvytas and angelll, both solutions worked for me, and you've both been a great help. :)
0

Featured Post

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL help 5 51
SSIS how to COMPARE a data column from different servers? 6 90
How to disable/enable multiple sql jobs in efficient way 11 100
Query to Add Late Tolerance 10 61
There are some very powerful Data Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a discu…
Introduction This article will provide a solution for an error that might occur installing a new SQL 2005 64-bit cluster. This article will assume that you are fully prepared to complete the installation and describes the error as it occurred durin…
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now