Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to get this xml in row format

XML
<WorkOrders>
  <WorkOrder>
    <RackSet>
      <Rack>SN1</Rack>
      <Rack>SN2</Rack>
      <Rack>SN3</Rack>
      <Rack>SN4</Rack>
    </RackSet>
  </WorkOrder>
</WorkOrders>


I want result like this:

SN1
SN2
SN3
SN4

Can anybody help?
Posted
Comments
Zoltán Zörgő 8-Jul-13 8:27am    
Is this value a field in a record, and you want all nested "rack"-s from all records?

Try this.

SQL
SELECT *
FROM OPENXML(@docHandle, N'/WorkOrders/WorkOrder/RackSet/Rack')
 
Share this answer
 
Try this:
SQL
DECLARE @iDoc INT /* Stores a pointer to the XML document */
DECLARE @foo as xml
set @foo=N'<workorders>
  <workorder>
    <rackset>
      <rack>SN1</rack>
      <rack>SN2</rack>
      <rack>SN3</rack>
      <rack>SN4</rack>
    </rackset>
  </workorder>
</workorders>'


EXEC sp_xml_preparedocument @iDoc OUTPUT, @foo

SELECT Racks.value('(Rack)[1]','nvarchar(30)') as Rack1,
Racks.value('(Rack)[2]','nvarchar(30)') as Rack2,
Racks.value('(Rack)[3]','nvarchar(30)') as Rack3,
Racks.value('(Rack)[4]','nvarchar(30)') as Rack4
FROM @foo.nodes('*/*/*') as foo(Racks)

EXEC sp_xml_removedocument @iDoc
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900