I have below piece of XML as part of XML column in table say MyTable
<policystatusdetail id="XXXXXXXXXXXXXXX">
<CurrentUser>ABCDEFG</CurrentUser>
<LastModifiedDateTime>2016-04-02T17:03:01.761</LastModifiedDateTime>
<PolicyStatus>Quote-New-Pending</PolicyStatus>
</policystatusdetail>
I want to extract only PolicyStatus as column.
I am using below query
Select x.r.value('@PolicyStatus','varchar(500)') as PolicyStatus
from
(Select cast(XMLData as XML) XMLData from Mytable) s
cross apply s.XMLData.nodes('session/data/policyAdmin/policyStatusdetail') as x(r)
But it returns zero rows. Can anyone help?
policystatusdetail, you need to look for the nodepolicystatusdetail, notpolicyStatusdetail. Also,PolicyStatus[1], not@PolicyStatus. Using what you're currently using, it will look for the attribute "PolicyStatus" in the policystatusdetail node (e.g. to find "id", you'd use@id).