处理表字符分割

SELECT *
FROM
(
SELECT
B.value
FROM
(
SELECT
value = CONVERT(XML, '<root><v>' + REPLACE(Months, ',', '</v><v>') + '</v></root>')
FROM #NaMonth
) A
OUTER APPLY
(
SELECT value = N.v.value('.', 'varchar(100)')
FROM a.[value].nodes('/root/v') N(v)
) B
) AS cc;

 

// 第二种

SELECT TOP 1
@Mon = STUFF(
(
SELECT ',' + a.Months
FROM #Months a
LEFT JOIN
(SELECT code FROM dbo.f_split(c.Months + ',', ',') ) b
ON a.Months = b.code
FOR XML PATH('')
),
1,
1,
''
)
FROM #Months c;

posted @ 2018-12-18 15:49  奔跑的熊猫  阅读(160)  评论(0编辑  收藏  举报