I am trying to extract value from xml in table.PFB sample xml.
<?xml version="1.0" encoding="utf-16"?>
<ArrayOfKeyValue xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<KeyValue>
<Key>[#Id#]</Key>
<Value>354005</Value>
</ArrayOfKeyValue>
I am trying below script and it is not working.
SELECT
CAST(CAST(([KeyWordValues]) AS ntext) AS XML).value('(/ArrayOfKeyValue/KeyValue[1])', 'nvarchar(max)')
FROM
Table
I'm getting this error :
Msg 2389, Level 16, State 1, Line 1
XQuery [value()]: 'value()' requires a singleton (or empty sequence), found operand of type 'xdt:untypedAtomic *'
Please note XML is saved as varchar
in the database.
Please help. Thanks in advance