Sql server e XPath/manifest out/consol。但是您使用的是从根节点重新开始的g2.value()。这个解决方案看起来非常接近我的建议(只是有点错误;-))。然而:写你自己的答案和写thx的帮助是善良的,但没有人会看到这一点。今后,请在下面写下答

Sql server e XPath/manifest out/consol。但是您使用的是从根节点重新开始的g2.value()。这个解决方案看起来非常接近我的建议(只是有点错误;-))。然而:写你自己的答案和写thx的帮助是善良的,但没有人会看到这一点。今后,请在下面写下答,sql-server,xml,xpath,xml-parsing,xquery,Sql Server,Xml,Xpath,Xml Parsing,Xquery,e XPath/manifest out/consol。但是您使用的是从根节点重新开始的g2.value()。这个解决方案看起来非常接近我的建议(只是有点错误;-))。然而:写你自己的答案和写thx的帮助是善良的,但没有人会看到这一点。今后,请在下面写下答案,以向您的助手致意,并再提示一点:表示Thx的方式是投票和/或接受答案。 SELECT @xml.value('(/manifest-out/ediCustomerNumber/text())[1]','varchar(50)') AS cu

e XPath
/manifest out/consol
。但是您使用的是从根节点重新开始的
g2.value()。这个解决方案看起来非常接近我的建议(只是有点错误;-))。然而:写你自己的答案和写thx的帮助是善良的,但没有人会看到这一点。今后,请在下面写下答案,以向您的助手致意,并再提示一点:表示Thx的方式是投票和/或接受答案。
SELECT @xml.value('(/manifest-out/ediCustomerNumber/text())[1]','varchar(50)') AS customer_id 
      ,@xml.value('(/manifest-out/ediReference/text())[1]','varchar(50)') AS reference
      ,(
        SELECT gl.value('(quantity/text())[1]','decimal(14,10)') AS unitamount
              ,gl.value('(grossWeight/text())[1]','decimal(14,10)') AS [weight]
              ,gl.value('(loadingMeters/text())[1]','decimal(14,10)') AS loadingmeter
        FROM @xml.nodes('/manifest-out/consol/file/goodsLine') A(gl)
        FOR XML PATH('cargo'),TYPE
       ) 
FOR XML PATH('shipment');
<shipment>
  <customer_id>*******</customer_id>
  <reference>*******</reference>
  <cargo>
    <unitamount>3.0000000000</unitamount>
    <weight>415.0000000000</weight>
    <loadingmeter>1.6330000000</loadingmeter>
  </cargo>
  <cargo>
    <unitamount>1.0000000000</unitamount>
    <weight>605.0000000000</weight>
    <loadingmeter>4.6330000000</loadingmeter>
  </cargo>
  <cargo>
    <unitamount>2.0000000000</unitamount>
    <weight>75.0000000000</weight>
    <loadingmeter>2.6330000000</loadingmeter>
  </cargo>
</shipment>
DECLARE @xml XML = '<manifest-out type="tag">
    <ediCustomerNumber>*******</ediCustomerNumber>
    <ediCustomerDepartment>Ic</ediCustomerDepartment>
    <transmitter>R</transmitter>
    <receiver>*******</receiver>
    <ediReference>*******</ediReference>
    <referenceIndication>0</referenceIndication>
    <internalShipmentNumber>*******</internalShipmentNumber>
    <ediFunction1>6</ediFunction1>
    <dateTimeZone>2019-07-24T13:05:55+02:00</dateTimeZone>
    <fileHeader type="tag">
    </fileHeader>
    <consol type="tag">
        <file type="tag">
            <operationalPeriod>2019/07</operationalPeriod>
            <loadingDate>2019-07-17</loadingDate>
            <loadingTime>00:00:00</loadingTime>
            <unloadingDate>2019-07-26</unloadingDate>
            <unloadingTime>17:00:00</unloadingTime>
            <primaryReference>8017883827</primaryReference>
            <deliveryTerm>DAP</deliveryTerm>
            <codeShedHandling>true</codeShedHandling>
            <goodsLine type="tag">
                <quantity>3.000</quantity>
                <grossWeight>415.000</grossWeight>
                <loadingMeters>1.633</loadingMeters>
            </goodsLine>
            <goodsLine type="tag">
                <quantity>1.000</quantity>
                <grossWeight>605.000</grossWeight>
                <loadingMeters>4.633</loadingMeters>
            </goodsLine>
            <goodsLine type="tag">
                <quantity>2.000</quantity>
                <grossWeight>75.000</grossWeight>
                <loadingMeters>2.633</loadingMeters>
            </goodsLine>
        </file>
    </consol>
</manifest-out>';

SELECT @xml.query('<shipment>
<customerID>{data(/manifest-out/ediCustomerNumber)}</customerID>
<CustomerDepartment>{data(/manifest-out/ediCustomerDepartment)}</CustomerDepartment>
{
for $x in /manifest-out/consol/file/goodsLine
return <cargo>
   <unitamount>{data($x/quantity)}</unitamount>
   <weight>{data($x/grossWeight)}</weight>
   <loadingmeter>{data($x/loadingMeters)}</loadingmeter>
 </cargo>
}
</shipment>');
<shipment>
  <customerID>*******</customerID>
  <CustomerDepartment>Ic</CustomerDepartment>
  <cargo>
    <unitamount>3.000</unitamount>
    <weight>415.000</weight>
    <loadingmeter>1.633</loadingmeter>
  </cargo>
  <cargo>
    <unitamount>1.000</unitamount>
    <weight>605.000</weight>
    <loadingmeter>4.633</loadingmeter>
  </cargo>
  <cargo>
    <unitamount>2.000</unitamount>
    <weight>75.000</weight>
    <loadingmeter>2.633</loadingmeter>
  </cargo>
</shipment>
SELECT @xml.query('<root>
{
for $x in /manifest-out/consol
return <shipment>
    <customerID>{data(/manifest-out/ediCustomerNumber)}</customerID>
    <CustomerDepartment>{data(/manifest-out/ediCustomerDepartment)}</CustomerDepartment>
    {
        for $c in $x/file/goodsLine
            return <cargo>
                    <unitamount>{data($c/quantity)}</unitamount>
                    <weight>{data($c/grossWeight)}</weight>
                    <loadingmeter>{data($c/loadingMeters)}</loadingmeter>
                </cargo>
    }
</shipment>
}
</root>');