Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
mixedupone3
Starting Member
8 Posts |
Posted - 2002-02-27 : 16:35:40
|
| Hello,I am trying to match a dialed phone number in one table to its rate in a different table. It is easy if the rate table was all of one length. number rate011521 .02011522 .01011523 .01I would use SUBSTRING(cdr.[dialed_number],1,6) = rate.[number]But the rate table has numbers of variable length.number rate01152331 .050115233 .02011523 .01011524 .010115223 .020115221 .0101152 .04I need a way to match to the most significant number of digits. Ex: Match 0115233 at .02 when the dialed number is 01152334569855.Any help would be very appreciated. |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2002-02-27 : 16:57:16
|
| Don't you want to allocate diferent rate cards to different accounts?select rate.ratefrom rate, cdrwhere cdr.[dialed_number] like rate.[number] + '%'to get the longest probably the most efficient way is to match on the longest and work your way downPut the cdrs you want to rate into a temp table #rate(cdr, rate)thendeclare @i intselect @i = max(len(rate.[number]) from ratewhile @i > 1beginupdate #rateset rate = rate.ratewhere left(#rate.[dialed_number],@i) = rate.[number]and #rate.rate is nullendI wrote something about writing an efficient telecom rating system some time ago - I'll try to dig it out.==========================================Cursors are useful if you don't know sql.Beer is not cold and it isn't fizzy. |
 |
|
|
mixedupone3
Starting Member
8 Posts |
Posted - 2002-02-28 : 12:26:52
|
| Can't thank you enough. I have struggled with this all week. The following worked!! Took me a while to get the temp table working correctly. All I have to do now is incorporate this query into a perl script to produce reports. And yes I will have different rates for different accounts. I will have A different rate table per account, and Perl will create variables to be substituted into the query in place of the table name 'rate'.declare @i intselect @i = max(len(rate.[number])) from ratewhile @i > 1beginupdate #temprate set #temprate.rate = (select rate.rate from rate where ((left(#temprate.[dialed_number],@i)) = rate.[number])) where #temprate.rate is nullset @i = (@i - 1)endI would be interested in anything you have on an "efficient telecom rating system " |
 |
|
|
|
|
|