if exists(select 1 from sysobjects where name='char_index')
drop function char_index go
create function char_index(@string varchar(8000),@char varchar(10),@index smallint)
--@string:待查找字符串,@index:查找位置
returns smallint
as
begin
 
declare
 
@i int,--当前找到第@i个
  @position int--所在位置
  set @position=1;
 
set @i=0;
 
while charindex(@char,@string,@position)>0
 
begin
   
set @position=charindex(@char,@string,@position)+1;
   
set @i=@i+1;
   
if @i=@index
   
begin
    
return @position-1;
   
end
 
end
 
return 0;--0表示未找到
end
go

相关文章:

  • 2021-07-16
  • 2021-11-04
  • 2021-12-12
  • 2022-01-07
  • 2021-11-20
  • 2021-11-04
  • 2021-11-04
  • 2021-11-18
猜你喜欢
  • 2021-11-17
  • 2021-11-04
  • 2021-12-15
  • 2021-11-17
  • 2020-07-19
  • 2021-12-12
  • 2021-11-04
  • 2021-11-17
相关资源
相似解决方案