1. 程式人生 > >處理表字元分割

處理表字元分割

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;