Converting phone LETTERS into DIGITS in T-SQL / MS SQL Server


How to convert letters used in phone numbers into digits, i.e. input string '1-800-FLOWERS' should return '1-800-3569377', using a T-SQL? In Oracle, I would have used PL/SQL TRANSLATE function, however I need to do it in T-SQL and there is no similar function in T-SQL.

Please take a look at this image - this is the transformation I am looking for Thanks!

enter image description here

1 Answer

Here is my solution:

  1. create dbo.Translate function by running a T-SQL script from this answer
  2. use the follwing code to process phone letters into their corresponding digits:


select dbo.Translate('1-800-FLOWERS', 'abcdefghijklmnopqrstuvwxyz', '22233344455566677778889999')

(1 row(s) affected)

You could also take a look here if you need to do phone letters translation in JavaScript


Post Answer