0

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

1
  • How did your attempt to solve this problem end up? Commented Jul 20, 2013 at 20:44

2 Answers 2

3
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)

SQL FIDDLE EXAMPLE

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Roman, i got what i want from your answer thanks again
0

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.