使用方式:
SELECT AllItem AS BldGUID FROM dbo.fn_split('01.02.03','.')
函数:
![](https://i-blog.csdnimg.cn/blog_migrate/8f900a89c6347c561fdf2122f13be562.gif)
![](https://i-blog.csdnimg.cn/blog_migrate/961ddebeb323a10fe0623af514929fc1.gif)
1 2 GO 3 ALTER function [dbo].[fn_split](@SourceSql varchar(max),@StrSeprate varchar(10)) 4 returns @temp table(AllItem varchar(100)) 5 --实现split功能 的函数 6 as 7 begin 8 declare @i int 9 set @SourceSql=rtrim(ltrim(@SourceSql)) 10 set @i=charindex(@StrSeprate,@SourceSql) 11 while @i>=1 12 begin 13 insert @temp values(left(@SourceSql,@i-1)) 14 set @SourceSql=substring(@SourceSql,@i+1,len(@SourceSql)-@i) 15 set @i=charindex(@StrSeprate,@SourceSql) 16 end 17 if @SourceSql<>'\' 18 insert @temp values(@SourceSql) 19 return 20 END 21 GO