I want to read an XML nvarchar column:
<Attributes>
<Map>
<entry key="costcenter">
<value>
<List>
<String>R03e</String>
<String>L07e</String>
</List>
</value>
</entry>
<entry key="department" value="Information Technology"/>
<entry key="email" value="[email protected]"/>
<entry key="employeeId" value="1a2a3b4d"/>
<entry key="firstName" value="Paul"/>
<entry key="fullName" value="Paul.Walker"/>
<entry key="inactiveIdentity" value="FALSE"/>
<entry key="lastName" value="Walker"/>
<entry key="location" value="Austin"/>
<entry key="managerId" value="1a2c3a4d"/>
<entry key="region" value="Americas"/>
</Map>
</Attributes>
I want results in columns like this:
costSenter | department | email | employeeId | firstName | lastName | location | managerId | region
You can use
nodesxml method (more info here) to shred your xml, apply attribute filtering and extract the information fromvalueattribute.You can use
cross applyto extend this operation to all the<entry>tagsHere is a basic query that you can use as a starting point:
Results:
P.S. In the future please follow the advice you got in the comments: post the code you have tried so far highlighting the problems you were unable to solve.