![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
#2
| |||
| |||
|
|
Using SQL Server 2008 XML Data Type For A Column How can I recursively count all the nodes within a node... I have a node that is simply //MyNode[@Item="1"] There are many nodes beneath this one, and nodes within nodes, hence the recursive part. I want to count them. |
|
I would also like to get a list of the nodes, such as a list of all the values of @Item. |
#3
| |||
| |||
|
|
Derek Hart wrote: Using SQL Server 2008 XML Data Type For A Column How can I recursively count all the nodes within a node... I have a node that is simply //MyNode[@Item="1"] There are many nodes beneath this one, and nodes within nodes, hence the recursive part. I want to count them. Well with XPath/XQuery you could do e.g. count(//MyNode[@Item="1"]//*) to count all element nodes contained in that MyNode. But: MS SQL server supports only a very restricted form of XQuery so you will have to try yourself whether it accepts that expression or complains. I would also like to get a list of the nodes, such as a list of all the values of @Item. //MyNode[@Item="1"]//@Item gives you the Item attributes of everything contained in MyNode. But again I am not sure SQL server will support that expression. -- Martin Honnen --- MVP Data Platform Development http://msmvps.com/blogs/martin_honnen/ |
![]() |
| Thread Tools | |
| Display Modes | |
| |