I have a table RDCAlerts
with the following data in a column of type XML
called AliasesValue
:
<aliases>
<alias>
<aliasType>AKA</aliasType>
<aliasName>Pramod Singh</aliasName>
</alias>
<alias>
<aliasType>AKA</aliasType>
<aliasName>Bijoy Bora</aliasName>
</alias>
</aliases>
I would like to create a query that returns two rows - one for each alias and I've tried the following query:
SELECT
AliasesValue.query('data(/aliases/alias/aliasType)'),
AliasesValue.query('data(/aliases/alias/aliasName)'),
FROM [RdcAlerts]
but it returns just one row like this:
AKA AKA | Pramod Singh Bijoy Bora
You need to use the
CROSS APPLY
statement along with the.nodes()
function to get multiple rows returned.Look at the .nodes() method in Books Online: