if object_id(
'tempdb.dbo.#T'
)
is
not
null
drop
table
#T
create
table
#T (id
int
,
name
varchar
(8))
insert
into
#T
select
1,
'jame,job'
union
all
select
2,
'paul,mc'
union
all
select
3,
'carl'
;
with
T (id,P1,P2)
as
(
select
id,charindex(
','
,
','
+
name
),charindex(
','
,
name
+
','
)+1
from
#T
union
all
select
a.id,b.P2,charindex(
','
,
name
+
','
,b.P2)+1
from
#T a
join
T b
on
a.id=b.id
where
charindex(
','
,
name
+
','
,b.P2)>0
)
select
a.id,
name
=
substring
(a.
name
+
','
,b.P1,b.P2 - b.P1 - 1)
from
#T a
join
T b
on
a.id=b.id
order
by
1