How to count occurrences of a node in SQL XML? How to count occurrences of a node in SQL XML? xml xml

How to count occurrences of a node in SQL XML?


This will count the number of Colors nodes which is 1.

select @MyXML.value('count(/SampleXML/Colors)', 'int')

This will count the number of rows in Colors which is 5.

select @MyXML.value('count(/SampleXML/Colors/*)', 'int')


select @MyXML.value('count(/SampleXML/Colors)', 'INT') AS 'Count'