• here's how i started tackling it: strip everything out, and then format depending on 10 or 11 digit lengths.

    I think i'd remove letters and replace with their corresponding numbers...

    I'm ignoring inserting periods before and after words in the phone;

    /*

    HowsThis

    866.611.3847

    800.2KM.IDAR

    800.001.4015

    800.001.4015

    866.231.2244

    888.401.KOND1

    855.EZP.8107

    1.855.OKR.8107

    1.800.228.2244

    1.800.483.SAVE(7283)

    800.228.2244

    666.606.0399

    */

    IF OBJECT_ID('tempdb.[dbo].[#myphone]') IS NOT NULL

    DROP TABLE [dbo].[#myphone]

    create table #myphone (phno varchar(20))

    Insert into #myphone values ('(866) 611-3847')

    Insert into #myphone values ('(800) 2-KMIDAR')

    Insert into #myphone values ('(800)-001-4015')

    Insert into #myphone values ('(800)001-4015')

    Insert into #myphone values ('(866) 231-2244')

    Insert into #myphone values ('(888) 401-KOND1')

    Insert into #myphone values (' (855) EZP-8107')

    Insert into #myphone values ('1 (855) OKR-8107')

    Insert into #myphone values ('1-800-228-2244')

    Insert into #myphone values ('1-800-483-SAVE(7283)')

    Insert into #myphone values ('800 228 2244')

    Insert into #myphone values ('666 - 606 - 0399')

    SELECT * FROM #myphone

    CROSS APPLY(SELECT REPLACE(REPLACE(REPLACE(

    phno,'.',''), --dots

    '-',''), --dashes

    ' ','') --whitespace

    As FirstPass) AS SimpleClean

    CROSS APPLY(SELECT LEFT(FirstPass,6) As Section,

    RIGHT(FirstPass,LEN(FirstPass) -6) As RearSection,

    REPLACE(REPLACE(LEFT(FirstPass,6),'(',''),')','') + RIGHT(FirstPass,LEN(FirstPass) -6 ) As ReplacedSection) AS Parens

    CROSS APPLY(SELECT CASE

    WHEN LEFT(ReplacedSection,1)='1'

    THEN STUFF(STUFF(STUFF(ReplacedSection,2,0,'.'),6,0,'.'),10,0,'.')

    ELSE STUFF(STUFF(ReplacedSection,4,0,'.'),8,0,'.')

    END AS HowsThis) AS LowellsVersion

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!