Reputation: 927
I am trying to get result from XML data but only getting a value of first node.
create table #temp(xmlString nvarchar(max))
insert into #temp (xmlString) values
('<?xml version="1.0" ?><response status = "ERROR">
<error>Error1</error>
<error>Error2</error>
</response>')
I want a result :
Error1, Error2
Please help. Thanks
Upvotes: 0
Views: 442
Reputation: 927
correct answer
select STUFF((select ',' + x.c.value('.', 'nvarchar(max)')
from (select cast(xmlString as xml) as data from #temp)
as t outer apply t.data.nodes('/response/error')
as x(c)for xml path('')), 1, 1, '') as Errors
Upvotes: 0
Reputation: 117380
select
x.c.value('.', 'nvarchar(128)') as value
from (select cast(xmlString as xml) as data from temp) as t
outer apply t.data.nodes('/response/error') as x(c)
Upvotes: 3