Hi-
How about something like the following. It may have some bugs but can be used as a starting point.
drop procedure sp_splitIntoIndividualComponents
go
create procedure sp_splitIntoIndividualComponents
As
declare @STR varchar(200)
set @STR = '2,3,4,5,6,7,8,9,'
;With t1(n1, str1, str2, n)
as
(
select1,convert(varchar(200), (substring(@str, 0, charIndex(',', @STR)))) str1,
convert(varchar(200), (substring(@str, charIndex(',', @STR) + 1, 20))) str2,
charIndex(',', @STR) as n
union all
select2,convert(varchar(200), (substring(t1.str2, 0, charIndex(',', t1.str2)))) str1,
convert(varchar(200), (substring(t1.str2, charIndex(',', t1.str2) + 1, 20))) str2,
charIndex(',', t1.str2) as n
from t1 where CHARINDEX(',', t1.str2) > 0
union all
select3,convert(varchar(200), t1.str2) str1,
'' str2,
charIndex(',', t1.str2) as n
from t1 where CHARINDEX(',', t1.str2) = 0 and (LEN(t1.str1) > 0 Or LEN(t1.str2) > 0)
)
select t1.str1 into #t from t1 where t1.str1 <> ''
select * from #t
go
exec sp_splitIntoIndividualComponents
go