【问题标题】:select value from xml field in sql server 2014 [closed]从 sql server 2014 中的 xml 字段中选择值 [关闭]
【发布时间】:2018-02-06 09:07:25
【问题描述】:

This is My Xml File,Tt 是 Table 的一个字段,我如何从中选择?结果格式是:pIdentityCode,ApplyPercent,CI_Ability,CI_Base,CI_CancelType,CI_Years 我无法为其编写选择查询。如果有人知道,请告诉我。

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
  <s:Header>
    <To xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" s:mustUnderstand="1">http://SErvice.com/PublishEngineerToOthers/srvEngineerToOthers.svc</To>
    <Action xmlns="http://schemas.microsoft.com/ws/2005/05/addressing/none" s:mustUnderstand="1">http://tempuri.org/IsrvEngineerToOthers/SaveRef_Info</Action>
  </s:Header>
  <s:Body>
    <SaveRef_Info xmlns="http://tempuri.org/">
      <pCode>gdyFlNN847tyCqSLnUkm5w==</pCode>
      <pNidWorkItem>600348</pNidWorkItem>
      <pIdentityCode>1261919491</pIdentityCode>
      <pRefInfo xmlns:a="http://schemas.datacontract.org/2004/07/DataAccess.Engineers" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
        <a:ApplyPercent>100</a:ApplyPercent>
        <a:CI_Ability>2</a:CI_Ability>
        <a:CI_Base>2</a:CI_Base>
        <a:CI_CancelType>0</a:CI_CancelType>
        <a:CI_Years>1396</a:CI_Years>
        <a:CancelDate i:nil="true" />
        <a:CommitmentDate i:nil="true" />
        <a:ConfirmCoordinatorDate i:nil="true" />
        <a:ConfirmCoordinatorNisUser i:nil="true" />
        <a:ConfirmCoordinatorTime i:nil="true" />
        <a:ConfirmCoordinatorUserName i:nil="true" />
        <a:ConfirmDate>1396/08/21</a:ConfirmDate>
<a:CreditValue i:nil="true" />
    <a:DateOfRefrence>1396/08/21</a:DateOfRefrence>
    <a:EumCoordinatorStatus i:nil="true" />
    <a:IdentityCode i:nil="true" />
    <a:IsBuildingExecRepCompleteAndConfirm i:nil="true" />
    <a:IsCanceled>false</a:IsCanceled>
    <a:IsCommitment>false</a:IsCommitment>
    <a:IsConfirm>false</a:IsConfirm>
    <a:IsCoordinator>false</a:IsCoordinator>
    <a:IsDynamic i:nil="true" />
    <a:IsEngExecuter>false</a:IsEngExecuter>
    <a:IsEngOwner>false</a:IsEngOwner>
    <a:IsExecuterQta i:nil="true" />
    <a:IsFree>false</a:IsFree>
    <a:IsFriend>false</a:IsFriend>
    <a:IsRelease>false</a:IsRelease>
    <a:IsSwitchEngineer>false</a:IsSwitchEngineer>
    <a:NIdEng i:nil="true" />
    <a:NIdFil>00000000-0000-0000-0000-000000000000</a:NIdFil>
    <a:NIdMem i:nil="true" />
    <a:NIdOff i:nil="true" />
    <a:NIdRef>00000000-0000-0000-0000-000000000000</a:NIdRef>
    <a:NIdRef_tmp>0</a:NIdRef_tmp>
    <a:NidTask i:nil="true" />
    <a:RefComments />
    <a:ReferDate>1396/08/21</a:ReferDate>
    <a:ReferNidUser i:nil="true" />
    <a:RevokeCoordinatorUserName i:nil="true" />
    <a:SwitchEngineerDate i:nil="true" />
    <a:SysCI_ReferType>0</a:SysCI_ReferType>
  </pRefInfo>
</SaveRef_Info>

【问题讨论】:

  • @HoneyBadger 我编辑了,你能再看看吗?
  • 这不是一个完整/正确的 XML
  • @Raska 它是它的一部分,你需要什么?请告诉我?
  • 最好为 XML 提供适当的结束标签进行测试。无论如何,我已经发布了答案。
  • @Raska 我编辑了,请再看一遍

标签: sql sql-server xml


【解决方案1】:
;WITH XMLNAMESPACES('http://schemas.xmlsoap.org/soap/envelope/' as s, 'http://tempuri.org/' as ns)
SELECT t.saveref.value('*:pIdentityCode[1]','varchar(max)') AS pIdentityCode,
t.saveref.value('(*:pRefInfo/*:ApplyPercent)[1]','int') AS ApplyPercent,
t.saveref.value('(*:pRefInfo/*:CI_Ability)[1]','int') AS CI_Ability
FROM @X.nodes('/s:Envelope/s:Body/ns:SaveRef_Info') as  t(saveref)   

【讨论】:

  • 它对我不起作用
  • Omid,编辑了答案。这为您的 xml 提供了值。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-12-01
  • 1970-01-01
  • 2017-10-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多