一行拆多行
DECLARE @t TABLE ( code VARCHAR(10) , value VARCHAR(100) ); INSERT INTO @t SELECT 'A' , '1,4,5,6,3' UNION ALL SELECT 'B' , '3,5,7,8,1'; SELECT * FROM @t; SELECT a.code , b.vv FROM ( SELECT code , value = CAST('<v>' + REPLACE(value, ',', '</v><v>') + '</v>' AS XML) FROM @t ) a OUTER APPLY ( SELECT vv = t.c.value('.', 'int') FROM a.value.nodes('v') t ( c ) ) b
https://www.cnblogs.com/yjShow/archive/2012/09/19/2693996.html