[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

SQL Match Dialled Number to International Dialling Code

Posted on 2011-09-08
8
Medium Priority
?
318 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Integration Management Part 2
Screencast - Getting to Know the Pipeline
Suggested Courses

834 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