使用方式:
SELECT AllItem AS BldGUID FROM dbo.fn_split('01.02.03','.')
函数:
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