|
create table A (col1 int, col2 varchar (100))
insert A select 3456, '601988,600028, HK3988, HK0386'
union all select 3457, '601988,600028'
select top 8000 ID = identity (int, 1, 1) into #T from sysobjects, syscolumns
select col1, col2 = cast (substring (A.col2, B.ID, charindex (',', A.col2 + ',', B.ID) -B.ID) as varchar (20))
from A as A, #T as B
where B.ID <= len (A.col2) and charindex (',', ',' + A.col2, B.ID) = B.ID
order by col1
--result
col1 col2
----------- --------------------
3456 601988
3456 600028
3456 HK3988
3456 HK0386
3457 600028
3457 601988
(6 row (s) affected) |
|