if object_id('dbo.multiRow') is not null
drop function dbo.multiRow
GO
create function dbo.multiRow(@data varchar(max), @delims varchar(10))
returns table as return
with cte (one,rem)
as
(
select
rtrim(ltrim(LEFT(@data, charindex(@delims,@data+@delims)-1))),
substring(@data, charindex(@delims,@data+@delims)+LEN(@delims+'.')-1, LEN(@data))
where nullif(@data,'') is not null
union all
select
rtrim(ltrim(LEFT(rem, charindex(@delims,rem+@delims)-1))),
substring(rem, charindex(@delims,rem+@delims)+len(@delims+'.')-1, LEN(rem))
from cte
where nullif(rem,'') is not null
)
select one from cte where nullif(one,'') is not null
GO
|