Solved

SQL Match Dialled Number to International Dialling Code

Posted on 2011-09-08
8
261 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
Comment Utility
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]
Comment Utility
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
Comment Utility
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
Comment Utility
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 5

Assisted Solution

by:zvytas
zvytas earned 250 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Thanks I will take a look at this asap and let you know
0
 

Author Closing Comment

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

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

763 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

11 Experts available now in Live!

Get 1:1 Help Now