0

I have a table(dbo.Orders with 2 fields: Id (int) and OrderItem(xml).

XML in the OrderItem field:

<Placement>
  <Position />
  <SeriesTotal>1</SeriesTotal>
  <Series>1</Series>
  <SectionId>193</SectionId>
</Placement>

What I want is a SQL statement selecting Id and the value from the node.

SELECT Id,SectionId FROM dbo.Orders

Any ideas?

  • possible duplicate of [How to query for Xml values and attributes from table in SQL Server?](http://stackoverflow.com/questions/19165213/how-to-query-for-xml-values-and-attributes-from-table-in-sql-server) – Krishnraj Rana Apr 22 '15 at 10:52

1 Answers1

0

You can use the value() method to get the nth SectionId:

SELECT  o.ID,
        SectionID = o.OrderItem.value('(Placement/SectionId)[1]', 'INT')
FROM    dbo.Orders AS o;
GarethD
  • 68,045
  • 10
  • 83
  • 123