Skip to content
Advertisement

How to count occurrences of a node in SQL XML?

I am trying to do a count on the number of occurrences of the “Colors” node but have been so far unsuccessful.

Below is what I have tried so far.

If I have the following logic:

I get the following error:

Msg 2389, Level 16, State 1, Line 50
XQuery [value()]: ‘value()’ requires a singleton (or empty sequence), found operand of type ‘xdt:untypedAtomic *’

Advertisement

Answer

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

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

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement