Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从SQL中的XML数据提取属性详细信息_Sql_Sql Server_Xml - Fatal编程技术网

从SQL中的XML数据提取属性详细信息

从SQL中的XML数据提取属性详细信息,sql,sql-server,xml,Sql,Sql Server,Xml,我在SQL中有一列(attributes),其中包含XML数据。您能否建议如何从该XML数据中提取错误详细信息 我尝试了下面的查询,但它不起作用 SELECT top 10 identity_name, CAST (tr.attributes as xml).value('(Attributes/Map/entry/value/accountrequest/ProvisioningResult/Errors[@key="Message"])[1]/@value','nvarchar(200)'

我在SQL中有一列(attributes),其中包含XML数据。您能否建议如何从该XML数据中提取错误详细信息

我尝试了下面的查询,但它不起作用

SELECT top 10 identity_name,
CAST (tr.attributes as xml).value('(Attributes/Map/entry/value/accountrequest/ProvisioningResult/Errors[@key="Message"])[1]/@value','nvarchar(200)') as Message
From [identityiq].[identityiq].[spt_provisioning_transaction] as tr 
where id = '8aae1d866d49a4b2016d57852fc3503b'
XML数据如下所示

<Attributes>   <Map>     <entry key="accessRequestId" value="0000086661"/>     <entry key="request">       <value>         <AccountRequest application="Active Directory" nativeIdentity="123" op="Modify">           <Attributes>             <Map>               <entry key="provisioningTransactionId" value="8aae1d866cace49c016cf7e26a7f4a8a"/>             </Map>           </Attributes>           <AttributeRequest name="memberOf" op="Remove" value="Testgroup"/>           <ProvisioningResult>             <Errors>               <Message key="Errors returned from IQService. &quot;Failed to update attributes for identity 123. Failed to connect to the server for Testgroup&quot;" type="Error"/>             </Errors>           </ProvisioningResult>         </AccountRequest>       </value>     </entry>   </Map> </Attributes> 

注意区分大小写

declare @x xml = N'
<Attributes>
  <Map>
    <entry key="accessRequestId" value="0000086661" />
    <entry key="request">
      <value>
        <AccountRequest application="Active Directory" nativeIdentity="123" op="Modify">
          <Attributes>
            <Map>
              <entry key="provisioningTransactionId" value="8aae1d866cace49c016cf7e26a7f4a8a" />
            </Map>
          </Attributes>
          <AttributeRequest name="memberOf" op="Remove" value="Testgroup" />
          <ProvisioningResult>
            <Errors>
              <Message key="Errors returned from IQService. &quot;Failed to update attributes for identity 123. Failed to connect to the server for Testgroup&quot;" type="Error" />
            </Errors>
          </ProvisioningResult>
        </AccountRequest>
      </value>
    </entry>
  </Map>
</Attributes>
';

    select @x.value('(Attributes/Map/entry/value/AccountRequest/ProvisioningResult/Errors/Message[@type="Error"])[1]/@key','nvarchar(200)') as Message;
declare@x xml=N'
';
选择@x.value('(Attributes/Map/entry/value/AccountRequest/ProvisioningResult/Errors/Message[@type=“Error”])[1]/@key','nvarchar(200)”作为消息;
区分大小写。试试“属性”