使用方式:
SELECT AllItem AS BldGUID FROM dbo.fn_split('01.02.03','.')
函数:
GO
ALTER function [dbo].[fn_split](@SourceSql varchar(max),@StrSeprate varchar(10))
returns @temp table(AllItem varchar(100))
--实现split功能 的函数
as
begin
declare @i int
set @SourceSql=rtrim(ltrim(@SourceSql))
set @i=charindex(@StrSeprate,@SourceSql)
while @i>=1
begin
insert @temp values(left(@SourceSql,@i-1))
set @SourceSql=substring(@SourceSql,@i+1,len(@SourceSql)-@i)
set @i=charindex(@StrSeprate,@SourceSql)
end
if @SourceSql<>'\'
insert @temp values(@SourceSql)
return
END
GO