![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
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
测试:
select * from dbo.f_splitstr('1,2,3,4',',')aa dbo.f_splitstr('1,2,3,4',',') bb