Steven Steven - 1 year ago 147
SQL Question

Xquery get value from attribute

I have some xml and need to extract values using sql

<?xml version="1.0" ?>

<field name="fld_AccomAttic">
<field name="fld_AccomBathroom">


I need to get
column name


The xml is held in a sql server 2005 db

I have used xquery before and it has worked.

Can any one show me how to extract these values

Im baffeled as to why i am unable to do this


Answer Source
SELECT <xmlfield>.value('(/xml/fields/field/@name)[1]', 'varchar(60)')
FROM <table>
WHERE <xmlfield>.value('(/xml/fields/field/value/)[1], 'int') = 1

Replace with your table and field names.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download