IF OBJECT_ID('dbo.Split') IS NOT NULL
  DROP FUNCTION dbo.Split;
GO
create FUNCTION dbo.Split(@pattern as char, @content AS nvarchar(max)) RETURNS @tb TABLE
(
id int identity(1,1) ,
value nvarchar(max)
)
AS
begin
declare @matchIndex int;
set @matchIndex=charindex(@pattern, @content);
while(@matchIndex>0)
begin
insert into @tb(value) values(substring(@content,1,@matchIndex-1));
set @content=stuff(@content,1,@matchIndex,'');
set @matchIndex=charindex(@pattern, @content);
end
insert into @tb(value) values(@content);
return
end

posted on 2010-08-12 13:45  netfuns  阅读(167)  评论(0)    收藏  举报