-->Title:Generating test data
-->Author:wufeng4552
-->Date :2009-09-30 15:16:26
--字符串分段截取
declare @s varchar(50),@split varchar(2),@pos int,@splitlen int
select @s='a,b,ct,d,e,f,g',@split=',',@pos=3,@splitlen=len(@split+'a')-2
while @pos>1 and charindex(@split,@s+@split)>0
select @pos=@pos-1,@s=stuff(@s,1,charindex(@split,@s+@split)+@splitlen,'')
select left(@s,charindex(@split,@s+@split)-1)
/*
--------------------------------------------------
ct
*/
字符串分段截取
本文介绍了一种使用T-SQL实现的字符串分段截取方法。通过声明变量并利用WHILE循环结合STUFF函数,实现了从指定位置开始移除特定分隔符后的字符串,最终返回所需的子串。此方法适用于需要按特定字符进行字符串切割的场景。
2422

被折叠的 条评论
为什么被折叠?



