Given the following sample of XML and the select
statement that shreds the xml into a relation, what I need is the second column of the select
to be the ordinal of the category (ie 1 for the directions and 2 for the colours in this case).
Note: The literal value 'rank()' in the select is left a placeholder. I was poking around with using the rank
, but with no success.
declare @x xml
set @x = '
<root>
<category>
<item value="north"/>
<item value="south"/>
<item value="east"/>
<item value="west"/>
</category>
<category>
<item value="red"/>
<item value="green"/>
<item value="blue"/>
</category>
</root>'
select c.value('./@value', 'varchar(10)') as "ItemValue",
'rank()' as "CategoryNumber"
from @x.nodes('//item') as t(c)