[msSql]字符串插入指定字符串函数

总觉得ms sql 字符串函数不够多,今天趁着一小段闲时时间编写了一个字符串插入指定字符串函数。闲话不多说直接贴代码。大笑

--指定所以位置中插入指定字符串
create function fun_Insert(@txt nvarchar(2000),@index int,@chars nvarchar(2000))
returns nvarchar(4000)
as
begin
	declare @len int
	set @len=len(@txt)
	if @index<1 begin
		--插入第0位置
		return @chars+@txt
	end else if @index>=@len begin
		--插入末尾位置
		return @txt+@chars
	end
	--插入中间位置
	return substring(@txt,1,@index)+@chars+substring(@txt,@index+1,@len-@index)
end
go

测试:

--插入最前端
select dbo.fun_Insert('指定所以位置中插入指定字符串',0,'http://www.naoqiu.com')
--插入末端
select dbo.fun_Insert('指定所以位置中插入指定字符串',100,'http://www.naoqiu.com')
--插入中间部分
select dbo.fun_Insert('指定所以位置中插入指定字符串',5,'http://www.naoqiu.com')

哪位博友有更多的字符串函数分享分享。


给自己网站打个小广告:福州公交查询网


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值