• Think not of what to do to the row... think of what to do to the column... and, you don't have to do it all at once... Divide'n'Conquer. 😉

    --===== Create and populate a test table. This is NOT part of the solution

    DECLARE @PhoneNumbers TABLE (Original VARCHAR(30))

    INSERT INTO @PhoneNumbers (Original)

    SELECT '+44 (0) 1908 123 456' UNION ALL

    SELECT '+44 (0) 121 430 4992'

    SELECT Original,

    REPLACE(STUFF(PartialFormat,CHARINDEX(' ',PartialFormat),0,')'),'(',' (') AS Reformatted

    FROM (--==== Partially reformat the phone number by replacing the (0) and surrounding spaces

    -- with just a left parentheses...

    SELECT Original, REPLACE(Original, ' (0) ','(') AS PartialFormat FROM @PhoneNumbers

    ) d

    Yields...

    [font="Courier New"]Original Reformatted

    -------------------- ------------------

    +44 (0) 1908 123 456 +44 (1908) 123 456

    +44 (0) 121 430 4992 +44 (121) 430 4992[/font]

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)