<bdo id='3kMdi'></bdo><ul id='3kMdi'></ul>

<small id='3kMdi'></small><noframes id='3kMdi'>

    <i id='3kMdi'><tr id='3kMdi'><dt id='3kMdi'><q id='3kMdi'><span id='3kMdi'><b id='3kMdi'><form id='3kMdi'><ins id='3kMdi'></ins><ul id='3kMdi'></ul><sub id='3kMdi'></sub></form><legend id='3kMdi'></legend><bdo id='3kMdi'><pre id='3kMdi'><center id='3kMdi'></center></pre></bdo></b><th id='3kMdi'></th></span></q></dt></tr></i><div id='3kMdi'><tfoot id='3kMdi'></tfoot><dl id='3kMdi'><fieldset id='3kMdi'></fieldset></dl></div>

  1. <tfoot id='3kMdi'></tfoot>
    1. <legend id='3kMdi'><style id='3kMdi'><dir id='3kMdi'><q id='3kMdi'></q></dir></style></legend>

      CROSS APPLY 到命名空间,子节点返回重复记录

      时间:2023-06-07
      <legend id='Hmevn'><style id='Hmevn'><dir id='Hmevn'><q id='Hmevn'></q></dir></style></legend>
      <tfoot id='Hmevn'></tfoot>

          <tbody id='Hmevn'></tbody>

            <small id='Hmevn'></small><noframes id='Hmevn'>

              • <bdo id='Hmevn'></bdo><ul id='Hmevn'></ul>
                <i id='Hmevn'><tr id='Hmevn'><dt id='Hmevn'><q id='Hmevn'><span id='Hmevn'><b id='Hmevn'><form id='Hmevn'><ins id='Hmevn'></ins><ul id='Hmevn'></ul><sub id='Hmevn'></sub></form><legend id='Hmevn'></legend><bdo id='Hmevn'><pre id='Hmevn'><center id='Hmevn'></center></pre></bdo></b><th id='Hmevn'></th></span></q></dt></tr></i><div id='Hmevn'><tfoot id='Hmevn'></tfoot><dl id='Hmevn'><fieldset id='Hmevn'></fieldset></dl></div>
                本文介绍了CROSS APPLY 到命名空间,子节点返回重复记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                限时送ChatGPT账号..

                我有这个 xml(为了可读性删除了大部分).我得到错误的记录.为每个 CAS_Number 提取的化学名称错误.一个 CAS_Number 表示一种化学品.但在这里,对于相同的 CAS_number,我有不同的化学名称.

                I have this xml (removed most of it for readability). I get wrong records. Wrong chemical names fetched for every CAS_Number. One CAS_Number means one chemical. But here, for the same CAS_number, I have different chemical names.

                这是我交叉申请中的问题,但我无法弄清楚.

                It's the problem in my cross apply but I couldn't figure it out.

                <ArrayOfCatalogItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
                <CatalogItem Version="1">
                   <Msds xmlns="http://3ecompany.com/webservices/catalogitemxml">
                     <ProductIdentifiers xmlns="http://3ecompany.com/webservices/catalogitemxml">
                      <Identifier>M007628</Identifier>
                      <Source>CPN</Source>
                      <FirstExportDate xsi:nil="true" />
                      <LastExportDate xsi:nil="true" />
                      <FlaggedForResend xsi:nil="true" />
                    </ProductIdentifiers>
                     <Ingredients>
                        <ChemicalName>Hexane</ChemicalName>
                        <Cas>000110-54-3</Cas>
                        <AvgPercent>20.000000</AvgPercent>
                      </Ingredients>
                      <Ingredients>
                        <ChemicalName>2-Propanone</ChemicalName>
                        <Cas>000067-64-1</Cas>
                        <AvgPercent>20.000000</AvgPercent>
                      </Ingredients>
                      <Ingredients>
                        <ChemicalName>Petroleum gases, liquefied, sweetened</ChemicalName>
                        <Cas>068476-86-8</Cas>
                      </Ingredients>
                  </Msds>
                </CatalogItem>
                </ArrayOfCatalogItem>
                

                存储过程是这样的:

                DECLARE @XmlTable TABLE (XMLDATA XML)
                
                INSERT INTO @XmlTable(XMLData)
                    SELECT CONVERT(XML, BulkColumn) AS BulkColumn 
                    FROM OPENROWSET(BULK 'C:\AA.Sample.File.LUS.Pilly-oneCI.xml', SINGLE_BLOB) AS x;
                
                ;WITH XMLNAMESPACES ('http://3ecompany.com/webservices/catalogitemxml' as CI)
                SELECT 
                    --CIVersion = CI.value('@Version', 'int'),
                    Identifier = PID.value('(.)\[1\]', 'varchar(9)'),
                    Product_Name = MSDSPN.value('(.)\[1\]','varchar(100)'),
                    CAS_Number = CAS.value('(.)\[1\]', 'varchar(20)'),
                    Chemical_Name = CN.value('(.)\[1\]', 'varchar(100)')
                
                FROM
                    @XmlTable
                CROSS APPLY
                    XMLData.nodes('/ArrayOfCatalogItem/CatalogItem') AS XT(CI)
                OUTER APPLY
                    CI.nodes('CI:ProductIdentifiers/CI:Identifier') AS XT2(PID)
                CROSS APPLY
                    CI.nodes('CI:Msds/CI:Ingredients/CI:Cas') AS XT18(CAS)
                CROSS APPLY
                    CI.nodes('CI:Msds/CI:Ingredients/CI:ChemicalName') AS XT19(CN)
                

                推荐答案

                试试这个:

                ;WITH XMLNAMESPACES ('http://3ecompany.com/webservices/catalogitemxml' as CI)
                SELECT 
                    Identifier = CI.value('(CI:ProductIdentifiers[1]/CI:Identifier)[1]', 'varchar(9)'),
                    CAS_Number = Ingred.value('(CI:Cas)[1]', 'varchar(20)'),
                    Chemical_Name = Ingred.value('(CI:ChemicalName)[1]', 'varchar(100)')
                FROM
                    @XmlTable
                CROSS APPLY
                    XMLData.nodes('/ArrayOfCatalogItem/CatalogItem/CI:Msds') AS XT(CI)
                CROSS APPLY
                    CI.nodes('CI:Ingredients') AS XT18(Ingred)
                

                我获得了每个 节点的 XML 片段列表,并从中获取了 ProductIdentifiers 信息.另外,从这个节点,我还获得了 节点的子 XML 片段列表,并从中获取详细信息.

                I get a list of XML fragments for each <Msds> node, and from this I grab the ProductIdentifiers info. Plus, from this node, I also get a list of sub-XML-fragments for the <Ingredients> nodes, and grab detailed into from these.

                我的输出如下所示:

                这篇关于CROSS APPLY 到命名空间,子节点返回重复记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:T-SQL FOR XML 查询中的命名空间问题 下一篇:带有未声明前缀的 SQL Server Xml 查询

                相关文章

                最新文章

                <legend id='EJU9N'><style id='EJU9N'><dir id='EJU9N'><q id='EJU9N'></q></dir></style></legend>
                • <bdo id='EJU9N'></bdo><ul id='EJU9N'></ul>
              • <tfoot id='EJU9N'></tfoot>

                <i id='EJU9N'><tr id='EJU9N'><dt id='EJU9N'><q id='EJU9N'><span id='EJU9N'><b id='EJU9N'><form id='EJU9N'><ins id='EJU9N'></ins><ul id='EJU9N'></ul><sub id='EJU9N'></sub></form><legend id='EJU9N'></legend><bdo id='EJU9N'><pre id='EJU9N'><center id='EJU9N'></center></pre></bdo></b><th id='EJU9N'></th></span></q></dt></tr></i><div id='EJU9N'><tfoot id='EJU9N'></tfoot><dl id='EJU9N'><fieldset id='EJU9N'></fieldset></dl></div>

                <small id='EJU9N'></small><noframes id='EJU9N'>