Solved

SQL Match Dialled Number to International Dialling Code

Posted on 2011-09-08
8
303 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 143

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
Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

 

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
 
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 143

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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

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: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

691 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