I have a data stored in a xml column and need a comma-separated list of child nodes. Using script below, I can only get \"A B C\". Please help me get \"A,B,C\" using xquery
Try this:
SELECT
STUFF((SELECT
',' + fd.v.value('(.)[1]', 'varchar(10)')
FROM
Temp12345
CROSS APPLY
col1.nodes('/fd/field/v') AS fd(v)
FOR XML PATH('')
), 1, 1, '')
This gives me A,B,C
- does it work for you, too?
In a full complain XQuery processor you could use just:
(/fd/field[@i=22])[1]/string-join(*,',')