1 create function f_splitstr(
@SourceSql varchar(
8000),
@StrSeprate varchar(
100))
2 returns @temp table(F1
varchar(
100))
3 as
4 begin
5 declare @ch as varchar(
100)
6 set @SourceSql=@SourceSql+@StrSeprate
7 while(
@SourceSql<>'')
8 begin
9 set @ch=left(
@SourceSql,
charindex(
',',
@SourceSql,
1)
-1)
10 insert @temp values(
@ch)
11 set @SourceSql=stuff(
@SourceSql,
1,
charindex(
',',
@SourceSql,
1),
'')
12 end
13 return
14 end
View Code
测试:
select * from dbo.f_splitstr('1,2,3,4',',')aa dbo.f_splitstr('1,2,3,4',',') bb
转载于:https://www.cnblogs.com/work-at-home-helloworld/p/splitstr.html
相关资源:sqlserver中根据某个字符切割字符串函数