how to format phone number in ms sql server?


Sometimes it is desperately required to format the phone number before displaying them in your website. In this ms sql server tutorial we will learn how to format the phone number in mssql server query.
Actually we want to convert telephone number like this 6092758415 into (609) 275-8415. Let’s have a look over how to do this, for example we have a columnuser_phone in our database table users, let’s look how to format the telephone number in mssql server query. It's easy and better to perform formatting of phone numbers in sql.
 select case when len(ltrim(rtrim(User_Phone)))='10' then'('+SUBSTRING(User_Phone,1,3)+')'+' '+SUBSTRING(User_Phone,4,3)+'-'+SUBSTRING(User_Phone,7,4) when len(ltrim(rtrim(User_Phone)))='' then ' ' end ASUser_Phone from users
Now phone number field will show data in this format (###) ###-####
I hope you will like this ms sql server tutorial to format the phone number in this format (###) ###-####
Your Ad Here


Comments