CREATE function Split
(
@charString nvarchar(4000), --字符串
@separator char(1) --分割符
)
returns @tb_temp table (string nvarchar(4000))
as
begin
declare @beginIndex int,@separatorIndex int,@stringLength int
select @beginIndex = 1
select @stringLength = len(@charString)
while @beginIndex <= @stringLength
begin
select @separatorIndex = charIndex(@separator,@charString,@beginIndex)
declare @v_char nvarchar(4000)
if @separatorIndex = 0
select @separatorIndex = @stringLength + 1
select @v_char = substring(@charString,@beginIndex,@separatorIndex-@beginIndex)
insert into @tb_temp values (@v_char)
select @beginIndex = @separatorIndex + 1
end
return
end