ID PHONE
1 9701245929
2 66663333
3 9701245931
4 9701245932
5 26668888
6 48228899
7 88229933
OUTPUT:
ID PHONE
1 9701 245 929
2 6666 3333
3 9701 245 931
4 9701 245 932
5 2666 8888
6 4822 8899
7 8822 9933
ID PHONE
1 9701245929
2 66663333
3 9701245931
4 9701245932
5 26668888
6 48228899
7 88229933
OUTPUT:
ID PHONE
1 9701 245 929
2 6666 3333
3 9701 245 931
4 9701 245 932
5 2666 8888
6 4822 8899
7 8822 9933
You can use a query like below See working demo
select id,
phone=case
when
len(phone)=10
then
FORMAT(cast(phone as bigint), '### ### ###')
when
len(phone)=8
then
FORMAT(cast(phone as bigint), '#### ####')
end
from t;
You need format():
select format(PHONE, '### ### ###') as Phone
from table t;
Edit : You can use case expression for conditional formatting
select *, (case when len(Phone) = 8
then format(Phone, '#### ####')
else format(Phone, '#### ### ###')
end) as Phone
from table t;