I have worked with querying XML and I have what seems like it should be a pretty straightforward query.
My data is stored in XML format, such as this:
declare @data xml =
'<data-set xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Row>
<Dept>DepartmentName</Dept>
<FirstName>John</FirstName>
<LastName>Smith</LastName>
<Alias>JSmith</Alias>
<PhoneNo>5555555555</PhoneNo>
<Email>JSmith@company.com</Email>
<AcctNo>123456</AcctNo>
</Row>
<Row>
...
</Row>
</data-set>'
I am querying it using:
;WITH XMLNAMESPACES (DEFAULT 'http://www.w3.org/2001/XMLSchema-instance')
select
C.value('/Row[1]/Email[1]','varchar(max)')
C.value('/Row[1]/FirstName[1]','varchar(max)')
from @data.nodes('data-set') as T(C)
I have tried it with and without the '[1]' after the fields, without the NAMESPACE
and I have tried querying using //Email[1]
or @Email
but am having no luck. Any suggestions?