[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More
Experts Exchange Solution brought to you by
"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.
DECLARE @Text NVARCHAR(255) = N'1,2,<td>test</td>,4';
-- SQL Server 2016
FROM STRING_SPLIT(@Text, ',') SS;
WITH ToXml AS
SELECT CAST(('<td><![CDATA[' + REPLACE(@Text, ',', ']]></td><td><![CDATA[') + ']]></td>') AS XML) AS XmlData
SELECT td.value('.', 'NVARCHAR(255)') AS [value]
CROSS APPLY XmlData.nodes('td') A ( td );
Open in new window
Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.
DECLARE @s VARCHAR(100)
SELECT @s = 'Apples,Oranges,Mangoes,Grapes';
AS (SELECT ROW_NUMBER()
OVER(ORDER BY p1.NUMBER) AS sr,
FROM MASTER..spt_values p1
WHERE p1.TYPE = 'p'
AND p1.NUMBER BETWEEN 1 AND LEN(@s) + 2
AND SUBSTRING(',' + @s + ',',p1.NUMBER,1) = ',')
SELECT SUBSTRING(' ' + @s,a.NUMBER + 1,b.NUMBER - a.NUMBER - 1) AS Fruit
FROM cte a
INNER JOIN cte b
ON b.sr = a.sr + 1
From novice to tech pro — start learning today.
Premium members can enroll in this course at no extra cost.