傳入參數有字段串以及分隔符
CREATE function ufn_StrSplit(@str nvarchar(4000),@splitSign nvarchar(10))
returns @table table (itemid int identity(1,1),tempStr nvarchar(3000))
as
begin
while charindex(@splitSign,@str)>0
begin
insert into @table (tempStr)
select left(@str,charindex(@splitSign,@str)-1)
select @str=stuff(@str,1,charindex(@splitSign,@str)+len(@splitSign)-1,'')
end
insert @table (tempStr) select @str
return
end
例子:
select * From ufn_StrSplit('123,234',',')
返回集:1 123
2 234