hi ryan,
Let me present a quick example:
<orderInfo>
<item code="A001" category="FOOD" subcategory="Candies">
<description>Nestle Munch</description>
<qty>10</qty>
<rate>11.25</rate>
</item>
<item code="A002" category="FOOD" subcategory="Biscuits">
<description>Britania Good Day</description>
<qty>15</qty>
<rate>12.25</rate>
</item>
</orderInfo>
The following example extracts the attribute values:
SELECT
x
.item.value('@code[1]', 'VARCHAR(20)') AS ItemCode,
x
.item.value('@category[1]', 'VARCHAR(20)') AS category,
x
.item.value('@subcategory[1]', 'VARCHAR(20)') AS subcategory
FROM
@x.nodes('//orderInfo/item') AS x(item)
The following example extracts the values from xml nodes.
SELECT
x
.item.value('description[1]', 'VARCHAR(20)') AS description,
x
.item.value('qty[1]', 'INT') AS qty,
x
.item.value('rate[1]', 'FLOAT') AS rate
FROM
@x.nodes('//orderInfo/item') as x(item)
I am coming up with a new article which shows some advanced XML processing. I will present a few more practical examples in it. It will be on in the next few weeks.
.