分割字符串函数
create function f_split(@c varchar(2000),@split varchar(2))
returns @t table(col varchar(20))
as
begin
while(charindex(@split,@c)<>0)
begin
insert @t(col) values (substring(@c,1,charindex(@split,@c)-1))
set @c = stuff(@c,1,charindex(@split,@c),'')
end
insert @t(col) values (@c)
return
end
go
select * from dbo.f_split('dfkd,dfdkdf,dfdkf,dffjk',',')
源博客地址:https://www.cnblogs.com/vaevvaev/p/7018716.html
合并多行数据某列为一列:
select [value] = stuff((select ','+modmb003 from modmb detail where modmb=18 for xml path('')), 1, 1, '')
源博客地址:https://www.cnblogs.com/vaevvaev/p/7018716.html
使用实例(若看不懂可联系QQ群644147671)
![](https://img2018.cnblogs.com/blog/1313380/201810/1313380-20181017195848486-310165579.png)