I am using SQL Server 2008 and I found this solution which is only for SQL Server 2012 - what is the equivelant to format a phone number in SQL Server 2008?
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It only takes a minute to sign up.Sign up to join this community
there isn't a function that will do it for you. You can cast the phone number as a string then then parse out the parts and add hyphen
declare @phone int set @phone = '1232223333' select SUBSTRING(cast(@phone as varchar(10)),1,3)+'-'+SUBSTRING(cast(@phone as varchar(10)),4,3)+'-'+SUBSTRING(cast(@phone as varchar(10)),7,4)
Assuming that the [PhoneField] is 10 digits, such as '1234567890' then you could use STUFF to put the proper values in. E.g.
But please note that this only answers formatting a phone number for the 10-digit answers. If you are using internationally dialed numbers, you need to investigate the various forms of phone numbers you might need to handle.