declare @a varchar(100)
declare @b char(1)
declare @c int
declare @d varchar(100)
declare @e intset @d = ''
set @b = ''
set @e = 0
set @a = '12121ppppppp,iee12.f@#$%#,ss88'
set @c = len(@a)
while @c > 0
begin
set @b = substring(@a,@c,1)
set @c = @c - 1
set @e = ASCII(@b)
--print @e
if @e > 48 and @e < 57
begin
set @d = @d + CHAR(@e)
end
end
print @d
set @d = REVERSE(@d)
print @d
declare @b char(1)
declare @c int
declare @d varchar(100)
declare @e intset @d = ''
set @b = ''
set @e = 0
set @a = '12121ppppppp,iee12.f@#$%#,ss88'
set @c = len(@a)
while @c > 0
begin
set @b = substring(@a,@c,1)
set @c = @c - 1
set @e = ASCII(@b)
--print @e
if @e > 48 and @e < 57
begin
set @d = @d + CHAR(@e)
end
end
print @d
set @d = REVERSE(@d)
print @d
create function f_split(@str varchar(8000))
returns @re table(id int identity(1,1),a int)
as
begin
declare @i1 int,@i2 int
set @i1=patindex('%[0-9]%',@str)
while @i1>0
begin
select @str=substring(@str,@i1,8000)
,@i2=patindex('%[^0-9]%',@str)
,@i2=case when @i2<1 then len(@str)+1 else @i2 end
insert into @re(a) values(left(@str,@i2-1))
select @str=substring(@str,@i2+1,8000)
,@i1=patindex('%[0-9]%',@str)
end
return
end
go--调用函数得到结果:
select * from dbo.f_split('12121ppppppp,iee12.f@#$%#,ss88')drop function f_split
create function f_split(@str varchar(8000))
returns varchar(8000)
as
begin
declare @i1 int,@i2 int,@re varchar(8000)
select @re='',@i1=patindex('%[0-9]%',@str)
while @i1>0
select @str=substring(@str,@i1,8000)
,@i2=patindex('%[^0-9]%',@str)
,@i2=case when @i2<1 then len(@str)+1 else @i2 end
,@re=@re+' '+left(@str,@i2-1)
,@str=substring(@str,@i2+1,8000)
,@i1=patindex('%[0-9]%',@str)
set @re=substring(@re,2,8000)
return(@re)
end
go--调用函数得到结果:
select dbo.f_split('12121ppppppp,iee12.f@#$%#,ss88')drop function f_split