Format column

  • Hi

    I am trying to format a col (phone) in a table (prob thru a UDF).

    from 1234567890 to 123-456-7890.

    Any help

    Thanks

  • Here is one way (of many):

    Declare @len int;

    Declare @value varchar(10);

    --Set @value = '4567890';

    Set @value = '1234567890';

    Set @len = len(@value);

    Select @value, stuff(stuff(right('000' + @value, 10), 7, 0, '-'), 4, 0, '-');

    Jeff

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply