考虑这个XML:
<Employees>
<Person>
<ID>1000</ID>
<Name>Nima</Name>
<LName>Agha</LName>
</Person>
<Person>
<ID>1001</ID>
<Name>Ligha</Name>
<LName>Ligha</LName>
</Person>
<Person>
<ID>1002</ID>
<Name>Jigha</Name>
<LName>Jigha</LName>
</Person>
<Person>
<ID>1003</ID>
<Name>Aba</Name>
<LName>Aba</LName>
</Person>
</Employees>
我声明了一个XML
变量并将此XML分配给它。如何使用Sql Server 2008(TSQL)获取此XML变量中ID
个元素的数量?
答案 0 :(得分:16)
SELECT @XMLVariable.value('count(/Employees/Person/ID)', 'int') AS IDCount
答案 1 :(得分:4)
试试这个:
declare @xmlvar XML;
set @xmlvar ='<YOUR XML>';
select @xmlvar.value('count(/Employees/Person/ID)', 'INT') AS 'Count'