有这个一个问题请教大家望多多指点;
name tel
A 05515301598
B 01047895323
C 05515478953
D 01025165646
... ....
要求用SQL语句实现如下结果:
name tel
A 0551-5301598
B 010-47895323
C 0551-5478953
D 010-25165646
... ....
在线等……
...全文
2898打赏收藏
Update语句如何写
有这个一个问题请教大家望多多指点; name tel A 05515301598 B 01047895323 C 05515478953 D 01025165646 ... .... 要求用SQL语句实现如下结果: name tel A 0551-5301598 B 010-47895323 C 0551-5478953 D 010-25165646 ... .... 在线等……
Update tablename set
tel=case left(tel,2)
when '01' then left(tel,3)+'-'+right(tel,len(tel)-3)
when '02' then left(tel,3)+'-'+right(tel,len(tel)-3)
else left(tel,4)+'-'+right(tel,len(tel)-4)
end
update tablename
set tel=case when tel like '01%' or tel like '02%' then left(tel,3)+'-'+right(tel,len(rtrim(tel))-3)
else left(tel,4)+'-'+right(tel,len(rtrim(tel))-4)
end
insert into tel
select 'Luohy527','05515319681' union
select 'Buohy527','05515319683' union
select 'Cuohy527','05515319684' union
select 'Duohy527','01015319681' union
select 'Euohy527','05515319686' union
select 'Fuohy527','01053196872' union
select 'Guohy527','05515319689'
用update tablename
set tel=case when tel like '01%' or tel like '02%' then left(tel,3)+'-'+right(tel,len(tel)-3)
else left(tel,4)+'-'+right(tel,len(tel)-4)
end
后有如下结果:
Buohy527 0551-319683
Cuohy527 0551-319684
Duohy527 010-5319681
Euohy527 0551-319686
Fuohy527 010-3196872
Guohy527 0551-319689
Luohy527 0551-319681
中间的'05515319681' 53换成了“—”
update tablename
set tel=case when tel like '01%' or tel like '02%' then left(tel,3)+'-'+right(tel,len(tel)-3)
else left(tel,4)+'-'+right(tel,len(tel)-4)
end