Solved

SQL Match Dialled Number to International Dialling Code

Posted on 2011-09-08
8
290 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 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
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

 

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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
SQL Server 208R2 not recognizing DBF file in linked Server 11 60
Divide by zero error encountered. 2 42
Unable to save view in SSMS 21 73
SQL Query with Sum and Detail rows 2 54
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…
I've encountered valid database schemas that do not have a primary key.  For example, I use LogParser from Microsoft to push IIS logs into a SQL database table for processing and analysis.  However, occasionally due to user error or a scheduled task…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

791 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