Tuesday, 20 May 2008

XPath/XQuery SQL counting repeatable nodes in SQL Server 2005

XML is represented in a field, vchr_Xml on table A, trying to count entities - can use xpath in the sql/xquery to get the count of repeatable nodes.

select convert(int, convert(varchar(max),
convert(xml,{a.ntext_xmlRepresentation).query('count(/Entities/Entity)')))

from [DB].dbo.tbl_A A where A.uid_id = [GUID]

No comments: