SQL Server 将逗号分隔的字符串转成列

DECLARE @CardNo VARCHAR(4000)='524545,36545,514584,254154,545654,2546,6545,25642,5415'
SELECT B.CardNo 
FROM(
	SELECT CardNo = CONVERT(xml,'' + REPLACE(@CardNo, ',', '') + '')
) A OUTER APPLY
(
	SELECT CardNo = N.v.value('.', 'varchar(100)') 
	FROM A.CardNo.nodes('/root/v') N(v)
) B

 

你可能感兴趣的:(Sql,Server)