declare @ColumnXML xml =
'<XmlValues>
<XmlValue SomeId="1">aaaa</XmlValue>
<XmlValue SomeId="2">bbbb</XmlValue>
<XmlValue SomeId="3">cccc</XmlValue>
</XmlValues>
'
-- get all XML records
SELECT T.c.query('.') AS result
FROM @ColumnXML.nodes('/XmlValues/ XmlValue') T(c)
-- return the data from the xml as a table
SELECT T.c.value('@SomeId','nvarchar( 100)') as SomeId,
T.c.value('.', 'varchar(50)') as SomeValue
FROM @ColumnXML.nodes('/XmlValues/ XmlValue') T(c)
-- also you can do filters:
where T.c.value('@SomeId','nvarchar( 100)') = 2
No comments:
Post a Comment