Sql server 计算属性的出现次数?

Sql server 计算属性的出现次数?,sql-server,xml,tsql,select,Sql Server,Xml,Tsql,Select,我在一个大表中有一个XML列,如下所示,在TSQL中,如何计算属性(LCPID)出现的次数 谢谢 守则: <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Body>

我在一个大表中有一个XML列,如下所示,在TSQL中,如何计算属性(LCPID)出现的次数

谢谢


守则:

<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <PingAutoRequest xmlns="http://Reply.LeadMarketPlace.Services.Ping.ServiceContracts/2007/10/ServiceContracts">
      <AutomotiveLead>
        <LCPId>766</LCPId>
        <Zipcode>33544</Zipcode>
        <Make>Ford</Make>
        <Model>Escape</Model>
        <LeadType>New</LeadType>
        <Year>2013</Year>
        <Trim>FWD S</Trim>
        <ExteriorColor />
        <InteriorColor />
        <Transmission />
        <TradeIn>false</TradeIn>
        <LastFourPhoneDigits />
        <LastName />
      </AutomotiveLead>
    </PingAutoRequest>
  </soap:Body>
</soap:Envelope>

766
33544
河流浅水处
逃跑
新的
2013
FWD S
假的

好的,由于您的XML不包含任何内容(除了名称空间),我假设您的意思是要计算
的数量。如果是这样,那么你可以这样做

;使用XMLNAMESPACES('http://Reply.LeadMarketPlace.Services.Ping.ServiceContracts/2007/10/ServiceContracts'作为ns)
选择XmlColumn.value('(count(//ns:LCPId))','int')
从你的表名
注意,我们需要处理,分号不是错误。然后我们使用表达式
count(//ns:LCPId)
计算元素的数量

您可以在sqlfiddle上看到它的作用