select case when len(col)=11 then replace(col,substring(col,4,4),'****') when len(col)=8 then replace(col,substring(col,3,4),'****') when len(col)=10 then replace(col,substring(col,5,4),'****') from tb
select case when len(col)=11 then replace(col,substring(col,4,4),'****') when len(col)=8 then replace(col,substring(col,3,4),'****') when len(col)=10 then replace(col,substring(col,5,4),'****') else col end from tb
select case when len(tel) = 11 then left(tel,3) + '****' + right(tel,4) when len(tel) = 8 then left(tel,2) + '****' + right(tel,2) when len(tel) = 10 then left(tel,4) + '****' + right(tel,2) end from tb
use tempdb;/* create table t1 ( id int not null, --类型编号 content nvarchar(20) not null ); insert into t1(id,content) values (1,'13600117788'), (2,'23490012'), (3,'2123490012'), (3,'7333458901'); */ select case when id = 1 then left(content,3) + '****' + right(content,4) when id = 2 then left(content,2) + '****' + right(content,2) when id = 3 then left(content,4) + '****' + right(content,2) else content end as [content] from t1;
--假设以长度判断 select case when len(col)=11 then stuff(col,4,4,'****') when len(col)=8 then stuff(col,3,4,'****') when len(col)=10 then stuff(col,5,4,'****') else col end from tb
case when len(col)=11 then replace(col,substring(col,4,4),'****')
when len(col)=8 then replace(col,substring(col,3,4),'****')
when len(col)=10 then replace(col,substring(col,5,4),'****')
from
tb
case when len(col)=11 then replace(col,substring(col,4,4),'****')
when len(col)=8 then replace(col,substring(col,3,4),'****')
when len(col)=10 then replace(col,substring(col,5,4),'****') else col end
from
tb
when len(tel) = 8 then left(tel,2) + '****' + right(tel,2)
when len(tel) = 10 then left(tel,4) + '****' + right(tel,2)
end
from tb
use tempdb;/*
create table t1
(
id int not null, --类型编号
content nvarchar(20) not null
);
insert into t1(id,content)
values
(1,'13600117788'),
(2,'23490012'),
(3,'2123490012'),
(3,'7333458901');
*/
select
case
when id = 1 then left(content,3) + '****' + right(content,4)
when id = 2 then left(content,2) + '****' + right(content,2)
when id = 3 then left(content,4) + '****' + right(content,2)
else
content
end as [content]
from t1;
select
case when len(col)=11 then stuff(col,4,4,'****')
when len(col)=8 then stuff(col,3,4,'****')
when len(col)=10 then stuff(col,5,4,'****') else col end
from
tb