27,580
社区成员
发帖
与我相关
我的任务
分享
create function dbo.fn_num(@s nvarchar(100))
returns nvarchar(100)
as
begin
declare @s1 nvarchar(100),@i int
set @s1=''
set @i=1
while @i<=len(@s)
begin
set @s1=@s1+case when ascii(substring(@s,@i,1))>128 then '-' else substring(@s,@i,1) end
set @i=@i+1
end
return @s1
end
declare @s nvarchar(100)
set @s='asf命令已33435成功完成dfg56'
select dbo.fn_num(@s)
--drop function dbo.fn_num
结果:
/*
asf---33435----dfg56
*/
注明:汉字的ascii码值应该是大于128的,有点记不清?如果有误请纠正
declare @cstr varchar(max)
set @cstr='abc同12志34们56好efg啊'
;
with a1 as
(
select @cstr cstr,1 n
union all
select case when substring(cstr,n,1) like '[吖-座]' then stuff(cstr,n,1,'-') else cstr end,n+1
from a1
where n<=len(cstr)
)
select top 1 @cstr=cstr from a1 order by n desc Option(MAXRECURSION 0)
select @cstr