|
发表于 2020-7-11 00:30:01
|
显示全部楼层
select top 1000 id=identity(int,1,1) into #t from sysobjects,syscolumns
create table tableA(id int,gid varchar(8000))
insert tableA select 3456, '601988,600028,HK3988,HK0386'
insert tableA select 3457, '601988,600028'
go
select b.id,gid=substring(','+b.gid+',',a.id+1,charindex(',',','+b.gid+',',a.id+1)-a.id-1)
from #t a,tableA b
where substring(','+b.gid+',',a.id,1)=',' and len(b.gid)>a.id
order by a.id
drop table tablea,#T
/*结果
id gid
---------------
3456 601988
3457 601988
3457 600028
3456 600028
3456 HK3988
3456 HK0386
*/ |
|