xquery sql - SQL Server Query XML in Nvarchar(max) Field? -
i have xml stored in nvarchar(max) field. realize there xml data type, in case not stored way. let's xml structured following:
<root> <hdr> <name>aj</name> </hdr> <dtls> <dtl> <price>1</price> </dtl> <dtl> <price>7</price> </dtl> <dtl> <price>3</price> </dtl> </dtls> </root> what trying count of detail (dtl) nodes exist record. sure possible xpath/xquery, not sure how.
try this:
select cast(<your_xml_column> xml).query('count(//dtl)') <your_table> e.g:
declare @x nvarchar(max) set @x = '<root> <hdr> <name>aj</name> </hdr> <dtls> <dtl> <price>1</price> </dtl> <dtl> <price>7</price> </dtl> <dtl> <price>3</price> </dtl> </dtls> </root>' select cast(@x xml).query('count(//dtl)')
Comments
Post a Comment