Stuff函数

 

 

Stuff(expression1_Str,startIndex,lengthInt,expression2_Str)函数共有四个参数,
其功能是将expression1_Str中自startIndex位置起lengthInt个字符,然后将expression2插入到expression1_Str中的startIndex位置。startIndex 1

数据库表中有三个字段,要以xxxx-xxxxxx-xxxxxx的格式出,其中不位数的,在后面空格,即把231234879这样的三个数以如下形式出到表中:23__-1234__-879___的格式,色的下划线种颜色代表一个空格。

STUFF(SPACE(4),1,LEN(‘23’),’23’)+’-’+STUFF(SPACE(6),1,LEN(‘1234’),’1234’)+’-’+ STUFF(SPACE(6),1,LEN(‘879’),’879’),转换结果自然就23__-1234__-879___了。

Stuff函数另一

select stuff('string1',<starting position>,<length to delete from string 1>,'string2')

示例:

select stuff('youxiaofeng',2,1,'F')

从第二个字符始,掉一个字符,然后用'F'代替掉字符的位置,如果不需要掉字符,<length to delete from string 1>设为0即可。

注意:如果<starting position><length to delete from string 1 >的,或者<starting position>是大于<string 1>度的数,STUFF函数将返回NULL,如果指令的<length to delete from string 1>于从<starting position>位置到<string 1>尾的字符数,此函数将<string 1 ><starting position-1>截断

 本文感soloist 的提供

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值