I am trying to get the count of nodes in an XML field. but I always see 0 as the result. Here is how my query looks like.
DECLARE @XmlTable TABLE (XmlResult XML)
INSERT INTO @XmlTable EXECUTE [dbo].usp_GetBooks @EditionId=400
--select * from @XmlTable
SELECT
--Count number of nodes
COUNT(*) AS BooksCount
FROM
(
SELECT XmlResult FROM @XmlTable
) AS XmlTable(XmlColumn)
CROSS APPLY XmlColumn.nodes('./books/book') XmlTableFunction(XmlColumn2);
My XML Looks like :
<Version number ="1">
<books>
<book>
<name> </name>
<author></author>
</book>
<book>
<name> </name>
<author></author>
</book>
</books>
</Version>
<book>
ought to close with a</book>
(it doesn't - right now), and the<Version number =1>
is not valid - the 1 needs to be in quotes:<Version number="1">
– Housework