How to format a numeric column as phone number in SQL

后端 未结 10 1201
情深已故
情深已故 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-05 23:58

    Solutions that use SUBSTRING and concatenation + are nearly independent of RDBMS. Here is a short solution that is specific to SQL Server:

    declare @x int = 123456789
    select stuff(stuff(@x, 4, 0, '-'), 8, 0, '-')
    

提交回复
热议问题