拆分列值

declare @t table(a varchar(10),b varchar(20))
insert @t select 'A',  '1,2'
union all select 'B', '1,2,9'
union all select 'C', '5,6'

select
    a.a,
    b=substring(a.b, b.number, charindex(',', a.b + ',', b.number) - b.number)
from @t a,master..spt_values b
where b.type='p'
    and substring(',' + a.b,b.number,1) = ','

 

a          b                   
---------- --------------------
A          1
A          2
B          1
B          2
B          9
C          5
C          6

(所影响的行数为 7 行)

你可能感兴趣的:(c,table,insert)