How to format a numeric column as phone number in SQL

后端 未结 10 1187
情深已故
情深已故 2020-12-05 23:26

I have table in the database with a phone number column. The numbers look like this:

123456789

I want to format that to look like this:

10条回答
  •  清歌不尽
    2020-12-06 00:15

    I found that this works if wanting in a (123) - 456-7890 format.

    UPDATE table 
    SET Phone_number =  '(' +  
                        SUBSTRING(Phone_number, 1, 3) 
                        + ') ' 
                        + '- ' +
                        SUBSTRING(Phone_number, 4, 3) 
                        + '-' +
                        SUBSTRING(Phone_number, 7, 4) 
    

提交回复
热议问题