Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

parse xml

1 view
Skip to first unread message

Anonymous

unread,
Nov 14, 2009, 12:43:01 AM11/14/09
to
<SampleXML>
<Tables>
<Table value="abc" />
<Table value="123" />
</Tables>
<Fields>
<Field value="Name" />
<Field value="Price" />
</Fields>
</SampleXML>

I need to parse the above xml such that it returns the attributes in a flat
format,
e.g. abc,123
How can this be achieved using sql 2005


Balaji

unread,
Nov 16, 2009, 2:00:12 AM11/16/09
to
Hi

You can use openxml function.

Regards, Balaji

"Anonymous" <Anon...@discussions.microsoft.com> wrote in message
news:AF7244FC-53B5-4C42...@microsoft.com...

Bob

unread,
Nov 16, 2009, 6:26:11 AM11/16/09
to
Try this:

DECLARE @xml XML

SET @xml = '<SampleXML>


<Tables>
<Table value="abc" />
<Table value="123" />
</Tables>
<Fields>
<Field value="Name" />
<Field value="Price" />
</Fields>

</SampleXML>'


SELECT
root.x.value('(Table/@value, Field/@value)[1]', 'VARCHAR(50)') AS a,
root.x.value('(Table/@value, Field/@value)[2]', 'VARCHAR(50)') AS b
FROM @xml.nodes('SampleXML/*') root(x)

0 new messages