Ad
Formatting Phone Numbers In Non-US Format
I have the following code that I'm trying to refactor to format a phone number field in the format I need it in:
STUFF(STUFF(STUFF(REPLACE('02 212345678','02 2','02 '), 7, 0, ' '), 3, 0, ') '), 1, 0, '(')
It returns data currently as this:
(02) 123 45678
where I need it in this format
(02) 1234 5678
The problem is the extra space after the closing bracket and having 4 numbers either side.
Ad
Answer
Based on your example, does the following work for you?
with sampledata as (select '02 212345678' num)
select Concat(Stuff('() ',2,0,Left(num,2)), Stuff(Right(num,8),5,0,' '))
from sampledata
Ad
source: stackoverflow.com
Related Questions
- → How to make Laravel use my class instead of native PDO?
- → SQL: simple custom column in select doesn't work?
- → How to execute Stored Procedure from Laravel
- → Which database engine type should be specified for Microsoft SQL Database in Laravel?
- → How to troubleshoot PDOException?
- → laravel sql server stored procedure output
- → Issue with converting a date using Carbon
- → SQL microsoft query to Laravel 4.2
- → General error 20018 Cannot Continue the file execution because the session is in the Kill state
- → List names of all available MS SQL databases on server using python
- → Variable which replace DB of name in SSMS
- → Java: database connection. Where is my mistake?
- → How Can I use "Date" Datatype in sql server?
Ad