[MSSQL]文字列指定長文字の削除
--
--@count <=0
create function fun_Remove(@txt nvarchar(2000),@index int,@count int)
returns nvarchar(2000)
as
begin
declare @len int
set @len=len(@txt)
--@count <=0
if @count<1 begin
if @index <1 begin
return ''
end
return substring(@txt,0,@index)
end
if @index+@count<1 begin
-- <1
return @txt
end else if @index+@count>=@len begin
--
if @index<1 begin
return ''
end
return substring(@txt,0,@index)
end
--
if @index<1 begin
return substring(@txt,@index+1,@len-@index-@count)
end
return substring(@txt,0,@index)+substring(@txt,@index+@count,@len-@index-@count+1)
end
go
テストselect dbo.fun_Remove('http://www.naoqiu.com',5,1)
-- :http//www.naoqiu.com
変換元:http://blog.csdn.net/zhengdjin/article/details/7579736