0

Given the following xml variable:

    declare @x xml
    select @x = '<Details>
<Description>
<Attributes>
   <Name>A</Name>
   <Values><RecordId>1</RecordId><RecordId>2</RecordId></Values>
</Attributes>
<Attributes>
    <Name>B</Name>
    <Values><RecordId>3</RecordId><RecordId>4</RecordId></Values>
</Attributes>
</Description>
</Details>'

I am trying to get all Name values with all their RecordIds. I would like to do it in one statement. I have the following now.

create table #xml (element varchar(60))

insert into #xml
select RoleDetails.item.value('(Name)[1]', 'varchar(60)')
from 
  @x.nodes('/Details/Description/Attributes') AS RoleDetails(item)

The format I'm looking for would be:

A 1
  2

B 3
  4
Omnia9
  • 1,563
  • 4
  • 14
  • 39

1 Answers1

0

It became easier to save the subset in the XML format and allow for code to do XML manipulation.

Omnia9
  • 1,563
  • 4
  • 14
  • 39